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 +4 -4
- data/lib/activejob-status.rb +37 -35
- data/lib/activejob-status/progress.rb +43 -41
- data/lib/activejob-status/status.rb +45 -43
- data/lib/activejob-status/storage.rb +28 -26
- data/lib/activejob-status/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c2f5a9c1c18e978423df936f1df40e5ac10e97ec28782260fb3980edac85a8
|
4
|
+
data.tar.gz: f77a7dabc7c43e311af942ddb0218b9f044ebee1284190a37eb810e49da462c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db433d26e44683e749a86b8dae4ea426e002d2f3ef3c06aa36a731e75fb2ec7255ec81b36f4daa8c476326f4e45834c180b6d13c600ecd511a05bba800f23dc
|
7
|
+
data.tar.gz: 0a36fb9aa42f326a9d63c203f8c263c69b11f2d92ab438eaf59072aac20c994c655b6125c0d52496fedf9588d44135bcc4c12dbeef2e39f42246d43288de64eb
|
data/lib/activejob-status.rb
CHANGED
@@ -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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
29
|
-
|
30
|
-
@@options = options
|
21
|
+
def status
|
22
|
+
@status ||= Status.new(self)
|
31
23
|
end
|
32
24
|
|
33
|
-
def
|
34
|
-
|
25
|
+
def progress
|
26
|
+
@progress ||= Progress.new(self)
|
35
27
|
end
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
class << self
|
30
|
+
def options=(options)
|
31
|
+
@@options = options
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module ActiveJob
|
2
|
+
module Status
|
3
|
+
module Storage
|
4
|
+
class << self
|
5
|
+
def store
|
6
|
+
ActiveJob::Status.store
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def options
|
10
|
+
ActiveJob::Status.options
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def job_id(job)
|
14
|
+
job.is_a?(String) ? job : job.job_id
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def key(job)
|
18
|
+
"activejob:status:#{job_id(job)}"
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def read(job)
|
22
|
+
store.read(key(job)) || {}
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def write(job, message)
|
26
|
+
store.write(key(job), message, expires_in: options[:expires_in])
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def update(job, message)
|
30
|
+
write(job, read(job).merge(message))
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def delete(job)
|
34
|
+
store.delete(key(job))
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
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
|
+
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: []
|