activejob-status 0.2.1 → 0.3.0
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/progress.rb +5 -5
- data/lib/activejob-status/status.rb +30 -7
- data/lib/activejob-status/storage.rb +3 -1
- data/lib/activejob-status/throttle.rb +3 -2
- data/lib/activejob-status/version.rb +3 -1
- data/lib/activejob-status.rb +17 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa59f53f6175aea2f38a219adfd4a707fc3fb8460265aeff78adc7b09a494f2
|
4
|
+
data.tar.gz: f8775e045b684ba6cc1215e2e7570ba8e7b4f10ad889d7fb5d78bea44a5b62f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15529aeaab2bf3e25a5a56fab998e867f9af6fd3f835b788a84f001f9f4be4f974c8e7e2d3d40f8f45b6d764b40984af69a11cc95c9edece1e6e987c8e5dee8
|
7
|
+
data.tar.gz: 48fa3e3ee20a768007b830b5f5019d958594c4ec26ffd8d0bdb8bcd7d0dbdbd8d6da63408df591bda657b5de93bc991f08f84b7b8076cf699ed86385671d72e2
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveJob
|
2
4
|
module Status
|
3
5
|
class Progress
|
@@ -7,21 +9,19 @@ module ActiveJob
|
|
7
9
|
delegate :status, to: :job, prefix: true
|
8
10
|
|
9
11
|
def initialize(job)
|
10
|
-
@job
|
11
|
-
@total
|
12
|
+
@job = job
|
13
|
+
@total = 100
|
12
14
|
@progress = 0
|
13
15
|
end
|
14
16
|
|
15
17
|
def total=(num)
|
16
18
|
@total = num
|
17
19
|
job_status.update(to_h, force: true)
|
18
|
-
self
|
19
20
|
end
|
20
21
|
|
21
22
|
def progress=(num)
|
22
23
|
@progress = num
|
23
24
|
job_status.update(to_h, force: true)
|
24
|
-
self
|
25
25
|
end
|
26
26
|
|
27
27
|
def increment(num = 1)
|
@@ -43,7 +43,7 @@ module ActiveJob
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_h
|
46
|
-
{
|
46
|
+
{progress: @progress, total: @total}
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveJob
|
2
4
|
module Status
|
3
5
|
class Status
|
@@ -5,22 +7,26 @@ module ActiveJob
|
|
5
7
|
delegate :queued?, :working?, :completed?, :failed?, to: :status_inquiry
|
6
8
|
|
7
9
|
def initialize(job, options = {})
|
8
|
-
options
|
9
|
-
@
|
10
|
-
@
|
10
|
+
options = ActiveJob::Status.options.merge(options)
|
11
|
+
@defaults = options.fetch(:includes, [])
|
12
|
+
@storage = ActiveJob::Status::Storage.new(options.without(:includes))
|
13
|
+
@job = job
|
11
14
|
end
|
12
15
|
|
13
16
|
def []=(key, value)
|
14
|
-
update({
|
17
|
+
update({key => value}, force: true)
|
15
18
|
end
|
16
19
|
|
17
20
|
def read
|
18
21
|
@storage.read(@job)
|
19
22
|
end
|
20
|
-
|
23
|
+
alias_method :to_h, :read
|
24
|
+
|
25
|
+
def update(payload, options = {})
|
26
|
+
@job.progress.instance_variable_set(:@progress, payload[:progress]) if payload.include?(:progress)
|
27
|
+
@job.progress.instance_variable_set(:@total, payload[:total]) if payload.include?(:total)
|
21
28
|
|
22
|
-
|
23
|
-
@storage.update(@job, message, **options)
|
29
|
+
@storage.update(@job, payload, **options)
|
24
30
|
end
|
25
31
|
|
26
32
|
def delete
|
@@ -46,6 +52,23 @@ module ActiveJob
|
|
46
52
|
def status_inquiry
|
47
53
|
status.to_s.inquiry
|
48
54
|
end
|
55
|
+
|
56
|
+
# Update default data
|
57
|
+
|
58
|
+
def update_defaults(status_key)
|
59
|
+
payload = {}
|
60
|
+
payload[:status] = status_key if @defaults.include?(:status)
|
61
|
+
payload[:serialized_job] = @job.serialize if @defaults.include?(:serialized_job)
|
62
|
+
update(payload, force: true)
|
63
|
+
end
|
64
|
+
|
65
|
+
def catch_exception(e)
|
66
|
+
payload = {}
|
67
|
+
payload[:status] = :failed if @defaults.include?(:status)
|
68
|
+
payload[:serialized_job] = @job.serialize if @defaults.include?(:serialized_job)
|
69
|
+
payload[:exception] = {class: e.class.name, message: e.message} if @defaults.include?(:exception)
|
70
|
+
update(payload, force: true)
|
71
|
+
end
|
49
72
|
end
|
50
73
|
end
|
51
74
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveJob
|
2
4
|
module Status
|
3
5
|
class Storage
|
@@ -5,7 +7,7 @@ module ActiveJob
|
|
5
7
|
options.assert_valid_keys(:expires_in, :throttle_interval)
|
6
8
|
|
7
9
|
@expires_in = options[:expires_in]
|
8
|
-
@throttle
|
10
|
+
@throttle = ActiveJob::Status::Throttle.new(options[:throttle_interval])
|
9
11
|
end
|
10
12
|
|
11
13
|
def store
|
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module ActiveJob
|
3
4
|
module Status
|
4
5
|
class Throttle
|
5
6
|
def initialize(interval)
|
6
|
-
@interval
|
7
|
+
@interval = interval
|
7
8
|
@started_at = Time.current
|
8
9
|
end
|
9
10
|
|
10
11
|
def wrap(force: false)
|
11
12
|
return yield if force || @interval.nil? || @interval.zero?
|
12
13
|
|
13
|
-
now
|
14
|
+
now = Time.current
|
14
15
|
elasped = now - @started_at
|
15
16
|
return if @interval > elasped
|
16
17
|
|
data/lib/activejob-status.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/hash"
|
5
|
+
require "activejob-status/storage"
|
6
|
+
require "activejob-status/status"
|
7
|
+
require "activejob-status/progress"
|
8
|
+
require "activejob-status/throttle"
|
6
9
|
|
7
10
|
module ActiveJob
|
8
11
|
module Status
|
9
12
|
extend ActiveSupport::Concern
|
10
13
|
|
11
|
-
DEFAULT_OPTIONS
|
12
|
-
expires_in:
|
13
|
-
throttle_interval: 0
|
14
|
+
DEFAULT_OPTIONS = {
|
15
|
+
expires_in: 60 * 30,
|
16
|
+
throttle_interval: 0,
|
17
|
+
includes: %i[status]
|
14
18
|
}.freeze
|
15
19
|
|
16
20
|
included do
|
17
|
-
before_enqueue { |job| job.status.
|
18
|
-
before_perform { |job| job.status.
|
19
|
-
after_perform
|
21
|
+
before_enqueue { |job| job.status.update_defaults(:queued) }
|
22
|
+
before_perform { |job| job.status.update_defaults(:working) }
|
23
|
+
after_perform { |job| job.status.update_defaults(:completed) }
|
20
24
|
|
21
25
|
rescue_from(Exception) do |e|
|
22
|
-
status.
|
26
|
+
status.catch_exception(e)
|
23
27
|
raise e
|
24
28
|
end
|
25
29
|
end
|
@@ -43,7 +47,7 @@ module ActiveJob
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def store=(store)
|
46
|
-
store
|
50
|
+
store = ActiveSupport::Cache.lookup_store(*store) if store.is_a?(Array) || store.is_a?(Symbol)
|
47
51
|
@@store = store
|
48
52
|
end
|
49
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob-status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Savater Sebastien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.3.7
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Monitor your jobs
|