activejob-status 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '069dbaec9c90cd38b7f3c776c8cb928c69e9e381da44a12859f90be51f2187c6'
4
- data.tar.gz: f75d3ba17eb3f9d56d1bc1abdbe343dc2f5b46e269bccc24c652e43dc6b0c618
3
+ metadata.gz: d2c2f5a9c1c18e978423df936f1df40e5ac10e97ec28782260fb3980edac85a8
4
+ data.tar.gz: f77a7dabc7c43e311af942ddb0218b9f044ebee1284190a37eb810e49da462c2
5
5
  SHA512:
6
- metadata.gz: 6a59ed17b1979cb50b385397f1d316c87e5d4a6563a7ca7f441fff4f8e8411ddfddb835664df7f7f93ad2c558b9bc782a396e9beb6ae6a546b55a9f60746a6fe
7
- data.tar.gz: d3be935b39e3685d81adeba2a544496ca8ee506e4b469bd060546d4d7e7114080fb5bae8635039091889afc292da379ebe24f5ac3405201fecce512bfc62568b
6
+ metadata.gz: 2db433d26e44683e749a86b8dae4ea426e002d2f3ef3c06aa36a731e75fb2ec7255ec81b36f4daa8c476326f4e45834c180b6d13c600ecd511a05bba800f23dc
7
+ data.tar.gz: 0a36fb9aa42f326a9d63c203f8c263c69b11f2d92ab438eaf59072aac20c994c655b6125c0d52496fedf9588d44135bcc4c12dbeef2e39f42246d43288de64eb
@@ -2,49 +2,51 @@ require 'activejob-status/storage'
2
2
  require 'activejob-status/status'
3
3
  require 'activejob-status/progress'
4
4
 
5
- module ActiveJob::Status
6
- extend ActiveSupport::Concern
7
- DEFAULT_EXPIRY = 60 * 30
8
-
9
- included do
10
- before_enqueue {|job| job.status.update(status: :queued) }
11
- before_perform {|job| job.status.update(status: :working) }
12
- after_perform {|job| job.status.update(status: :completed) }
13
-
14
- rescue_from(Exception) do |e|
15
- self.status.update(status: :failed)
16
- raise e
5
+ module ActiveJob
6
+ module Status
7
+ extend ActiveSupport::Concern
8
+ DEFAULT_EXPIRY = 60 * 30
9
+
10
+ included do
11
+ before_enqueue { |job| job.status.update(status: :queued) }
12
+ before_perform { |job| job.status.update(status: :working) }
13
+ after_perform { |job| job.status.update(status: :completed) }
14
+
15
+ rescue_from(Exception) do |e|
16
+ status.update(status: :failed)
17
+ raise e
18
+ end
17
19
  end
18
- end
19
-
20
- def status
21
- @status ||= Status.new(self)
22
- end
23
-
24
- def progress
25
- @progress ||= Progress.new(self)
26
- end
27
20
 
28
- class << self
29
- def options= options
30
- @@options = options
21
+ def status
22
+ @status ||= Status.new(self)
31
23
  end
32
24
 
33
- def options
34
- @@options ||= { expires_in: DEFAULT_EXPIRY }
25
+ def progress
26
+ @progress ||= Progress.new(self)
35
27
  end
36
28
 
37
- def store= store
38
- store = ActiveSupport::Cache.lookup_store(store) if store.is_a?(Symbol)
39
- @@store = store
40
- end
29
+ class << self
30
+ def options=(options)
31
+ @@options = options
32
+ end
41
33
 
42
- def store
43
- @@store ||= (defined?(Rails) && Rails.cache)
44
- end
34
+ def options
35
+ @@options ||= { expires_in: DEFAULT_EXPIRY }
36
+ end
37
+
38
+ def store=(store)
39
+ store = ActiveSupport::Cache.lookup_store(store) if store.is_a?(Symbol)
40
+ @@store = store
41
+ end
42
+
43
+ def store
44
+ @@store ||= (defined?(Rails) && Rails.cache)
45
+ end
45
46
 
46
- def get(id)
47
- Status.new(id)
47
+ def get(id)
48
+ Status.new(id)
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -1,44 +1,46 @@
1
- module ActiveJob::Status
2
- class Progress
3
- delegate :[], :to_s, :to_json, :inspect, to: :hash
4
-
5
- def initialize(job)
6
- @job = job
7
- @total = 100
8
- @progress = 0
9
- end
10
-
11
- def total=(num)
12
- @total = num
13
- update
14
- end
15
-
16
- def progress=(num)
17
- update { num }
18
- end
19
-
20
- def increment(num=1)
21
- update { @progress + num }
22
- end
23
-
24
- def decrement(num=1)
25
- update { @progress - num }
26
- end
27
-
28
- def finish
29
- update { @total }
30
- end
31
-
32
- private
33
-
34
- def update
35
- @progress = yield if block_given?
36
- @job.status.update(hash)
37
- self
38
- end
39
-
40
- def hash
41
- { progress: @progress, total: @total }
1
+ module ActiveJob
2
+ module Status
3
+ class Progress
4
+ delegate :[], :to_s, :to_json, :inspect, to: :hash
5
+
6
+ def initialize(job)
7
+ @job = job
8
+ @total = 100
9
+ @progress = 0
10
+ end
11
+
12
+ def total=(num)
13
+ @total = num
14
+ update
15
+ end
16
+
17
+ def progress=(num)
18
+ update { num }
19
+ end
20
+
21
+ def increment(num = 1)
22
+ update { @progress + num }
23
+ end
24
+
25
+ def decrement(num = 1)
26
+ update { @progress - num }
27
+ end
28
+
29
+ def finish
30
+ update { @total }
31
+ end
32
+
33
+ private
34
+
35
+ def update
36
+ @progress = yield if block_given?
37
+ @job.status.update(hash)
38
+ self
39
+ end
40
+
41
+ def hash
42
+ { progress: @progress, total: @total }
43
+ end
42
44
  end
43
45
  end
44
46
  end
@@ -1,46 +1,48 @@
1
- module ActiveJob::Status
2
- class Status
3
- delegate :[], :to_s, :to_json, :inspect, to: :read
4
- delegate :queued?, :working?, :completed?, :failed?, to: :status_inquiry
5
-
6
- def initialize(job)
7
- @job = job
8
- end
9
-
10
- def []= key, value
11
- update(key => value)
12
- end
13
-
14
- def read
15
- Storage.read(@job)
16
- end
17
-
18
- def update(message)
19
- Storage.update(@job, message)
20
- end
21
-
22
- def delete
23
- Storage.delete(@job)
24
- end
25
-
26
- def job_id
27
- Storage.job_id(@job)
28
- end
29
-
30
- def status
31
- read[:status]
32
- end
33
-
34
- def progress
35
- read[:progress].to_f / read[:total].to_f
36
- end
37
-
38
- def present?
39
- read.present?
40
- end
41
-
42
- def status_inquiry
43
- status.to_s.inquiry
1
+ module ActiveJob
2
+ module Status
3
+ class Status
4
+ delegate :[], :to_s, :to_json, :inspect, to: :read
5
+ delegate :queued?, :working?, :completed?, :failed?, to: :status_inquiry
6
+
7
+ def initialize(job)
8
+ @job = job
9
+ end
10
+
11
+ def []=(key, value)
12
+ update(key => value)
13
+ end
14
+
15
+ def read
16
+ Storage.read(@job)
17
+ end
18
+
19
+ def update(message)
20
+ Storage.update(@job, message)
21
+ end
22
+
23
+ def delete
24
+ Storage.delete(@job)
25
+ end
26
+
27
+ def job_id
28
+ Storage.job_id(@job)
29
+ end
30
+
31
+ def status
32
+ read[:status]
33
+ end
34
+
35
+ def progress
36
+ read[:progress].to_f / read[:total].to_f
37
+ end
38
+
39
+ def present?
40
+ read.present?
41
+ end
42
+
43
+ def status_inquiry
44
+ status.to_s.inquiry
45
+ end
44
46
  end
45
47
  end
46
48
  end
@@ -1,36 +1,38 @@
1
- module ActiveJob::Status
2
- module Storage
3
- class << self
4
- def store
5
- ActiveJob::Status.store
6
- end
1
+ module ActiveJob
2
+ module Status
3
+ module Storage
4
+ class << self
5
+ def store
6
+ ActiveJob::Status.store
7
+ end
7
8
 
8
- def options
9
- ActiveJob::Status.options
10
- end
9
+ def options
10
+ ActiveJob::Status.options
11
+ end
11
12
 
12
- def job_id(job)
13
- job.is_a?(String) ? job : job.job_id
14
- end
13
+ def job_id(job)
14
+ job.is_a?(String) ? job : job.job_id
15
+ end
15
16
 
16
- def key(job)
17
- "activejob:status:#{job_id(job)}"
18
- end
17
+ def key(job)
18
+ "activejob:status:#{job_id(job)}"
19
+ end
19
20
 
20
- def read(job)
21
- store.read(key(job)) || {}
22
- end
21
+ def read(job)
22
+ store.read(key(job)) || {}
23
+ end
23
24
 
24
- def write(job, message)
25
- store.write(key(job), message, expires_in: options[:expires_in])
26
- end
25
+ def write(job, message)
26
+ store.write(key(job), message, expires_in: options[:expires_in])
27
+ end
27
28
 
28
- def update(job, message)
29
- write(job, read(job).merge(message))
30
- end
29
+ def update(job, message)
30
+ write(job, read(job).merge(message))
31
+ end
31
32
 
32
- def delete(job)
33
- store.delete(key(job))
33
+ def delete(job)
34
+ store.delete(key(job))
35
+ end
34
36
  end
35
37
  end
36
38
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module Status
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
@@ -50,8 +50,9 @@ files:
50
50
  - lib/activejob-status/status.rb
51
51
  - lib/activejob-status/storage.rb
52
52
  - lib/activejob-status/version.rb
53
- homepage:
54
- licenses: []
53
+ homepage: https://github.com/inkstak/activejob-status
54
+ licenses:
55
+ - MIT
55
56
  metadata: {}
56
57
  post_install_message:
57
58
  rdoc_options: []