activejob-status 0.1.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activejob-status/progress.rb +47 -41
- data/lib/activejob-status/status.rb +48 -43
- data/lib/activejob-status/storage.rb +19 -11
- data/lib/activejob-status/throttle.rb +22 -0
- data/lib/activejob-status/version.rb +1 -1
- data/lib/activejob-status.rb +45 -36
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d578a534198cba31b4b8bbf48fb9d20625c630bca3f011985a08d570bb46fd3e
|
4
|
+
data.tar.gz: 78f27c54c8d486dd0332b6135cd43ca2fef7fb57414ebaca33d15941b45f9d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4519d605117f1df429a46f04fc2d670719adca040d3822260c4565d898e4f6c386cda28676df55a1b76f2177ad58606e0b3c7b1b0701621fea9f154590f57a
|
7
|
+
data.tar.gz: 6250e8d76b10e8b8fcc0e719456c1ad6f34fb5fb5d92973bc2b09990fb56f7c0337ac345b96e9fbf9402dbc1aa631273ee7b05cec997b5f3cd6cd6339d5e7235
|
@@ -1,44 +1,50 @@
|
|
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
|
+
attr_reader :job, :total, :progress
|
5
|
+
|
6
|
+
delegate :[], :to_s, :to_json, :inspect, to: :to_h
|
7
|
+
delegate :status, to: :job, prefix: true
|
8
|
+
|
9
|
+
def initialize(job)
|
10
|
+
@job = job
|
11
|
+
@total = 100
|
12
|
+
@progress = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def total=(num)
|
16
|
+
@total = num
|
17
|
+
job_status.update(to_h, force: true)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def progress=(num)
|
22
|
+
@progress = num
|
23
|
+
job_status.update(to_h, force: true)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def increment(num = 1)
|
28
|
+
@progress += num
|
29
|
+
job_status.update(to_h)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def decrement(num = 1)
|
34
|
+
@progress -= num
|
35
|
+
job_status.update(to_h)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def finish
|
40
|
+
@progress = @total
|
41
|
+
job_status.update(to_h, force: true)
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_h
|
46
|
+
{ progress: @progress, total: @total }
|
47
|
+
end
|
42
48
|
end
|
43
49
|
end
|
44
50
|
end
|
@@ -1,46 +1,51 @@
|
|
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, options = {})
|
8
|
+
options = ActiveJob::Status.options.merge(options)
|
9
|
+
@storage = ActiveJob::Status::Storage.new(options)
|
10
|
+
@job = job
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(key, value)
|
14
|
+
update({ key => value }, force: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read
|
18
|
+
@storage.read(@job)
|
19
|
+
end
|
20
|
+
alias to_h read
|
21
|
+
|
22
|
+
def update(message, options = {})
|
23
|
+
@storage.update(@job, message, **options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
@storage.delete(@job)
|
28
|
+
end
|
29
|
+
|
30
|
+
def job_id
|
31
|
+
@storage.job_id(@job)
|
32
|
+
end
|
33
|
+
|
34
|
+
def status
|
35
|
+
read[:status]
|
36
|
+
end
|
37
|
+
|
38
|
+
def progress
|
39
|
+
read[:progress].to_f / read[:total].to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
def present?
|
43
|
+
read.present?
|
44
|
+
end
|
45
|
+
|
46
|
+
def status_inquiry
|
47
|
+
status.to_s.inquiry
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
@@ -1,12 +1,15 @@
|
|
1
|
-
module ActiveJob
|
2
|
-
module
|
3
|
-
class
|
4
|
-
def
|
5
|
-
|
1
|
+
module ActiveJob
|
2
|
+
module Status
|
3
|
+
class Storage
|
4
|
+
def initialize(options = {})
|
5
|
+
options.assert_valid_keys(:expires_in, :throttle_interval)
|
6
|
+
|
7
|
+
@expires_in = options[:expires_in]
|
8
|
+
@throttle = ActiveJob::Status::Throttle.new(options[:throttle_interval])
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
9
|
-
ActiveJob::Status.
|
11
|
+
def store
|
12
|
+
@store ||= ActiveJob::Status.store
|
10
13
|
end
|
11
14
|
|
12
15
|
def job_id(job)
|
@@ -21,12 +24,17 @@ module ActiveJob::Status
|
|
21
24
|
store.read(key(job)) || {}
|
22
25
|
end
|
23
26
|
|
24
|
-
def write(job, message)
|
25
|
-
|
27
|
+
def write(job, message, force: false)
|
28
|
+
@throttle.wrap(force: force) do
|
29
|
+
store.write(key(job), message, expires_in: @expires_in)
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
|
-
def update(job, message)
|
29
|
-
|
33
|
+
def update(job, message, force: false)
|
34
|
+
@throttle.wrap(force: force) do
|
35
|
+
message = read(job).merge(message)
|
36
|
+
store.write(key(job), message, expires_in: @expires_in)
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
def delete(job)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module ActiveJob
|
3
|
+
module Status
|
4
|
+
class Throttle
|
5
|
+
def initialize(interval)
|
6
|
+
@interval = interval
|
7
|
+
@started_at = Time.current
|
8
|
+
end
|
9
|
+
|
10
|
+
def wrap(force: false)
|
11
|
+
return yield if force || @interval.nil? || @interval.zero?
|
12
|
+
|
13
|
+
now = Time.current
|
14
|
+
elasped = now - @started_at
|
15
|
+
return if @interval > elasped
|
16
|
+
|
17
|
+
yield
|
18
|
+
@started_at = now
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/activejob-status.rb
CHANGED
@@ -1,50 +1,59 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
1
2
|
require 'activejob-status/storage'
|
2
3
|
require 'activejob-status/status'
|
3
4
|
require 'activejob-status/progress'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
require 'activejob-status/throttle'
|
6
|
+
|
7
|
+
module ActiveJob
|
8
|
+
module Status
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
expires_in: 60 * 30,
|
13
|
+
throttle_interval: 0
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
included do
|
17
|
+
before_enqueue { |job| job.status.update(status: :queued) }
|
18
|
+
before_perform { |job| job.status.update(status: :working) }
|
19
|
+
after_perform { |job| job.status.update(status: :completed) }
|
20
|
+
|
21
|
+
rescue_from(Exception) do |e|
|
22
|
+
status.update(status: :failed)
|
23
|
+
raise e
|
24
|
+
end
|
17
25
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def status
|
21
|
-
@status ||= Status.new(self)
|
22
|
-
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
class << self
|
29
|
-
def options= options
|
30
|
-
@@options = options
|
27
|
+
def status
|
28
|
+
@status ||= Status.new(self)
|
31
29
|
end
|
32
30
|
|
33
|
-
def
|
34
|
-
|
31
|
+
def progress
|
32
|
+
@progress ||= Progress.new(self)
|
35
33
|
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
class << self
|
36
|
+
def options=(options)
|
37
|
+
options.assert_valid_keys(*DEFAULT_OPTIONS.keys)
|
38
|
+
@@options = DEFAULT_OPTIONS.merge(options)
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def options
|
42
|
+
@@options ||= DEFAULT_OPTIONS
|
43
|
+
end
|
44
|
+
|
45
|
+
def store=(store)
|
46
|
+
store = ActiveSupport::Cache.lookup_store(*store) if store.is_a?(Array) || store.is_a?(Symbol)
|
47
|
+
@@store = store
|
48
|
+
end
|
49
|
+
|
50
|
+
def store
|
51
|
+
@@store ||= (defined?(Rails) && Rails.cache)
|
52
|
+
end
|
45
53
|
|
46
|
-
|
47
|
-
|
54
|
+
def get(id)
|
55
|
+
Status.new(id)
|
56
|
+
end
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Savater Sebastien
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.2'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email:
|
43
43
|
- savater.sebastien@gmail.com
|
44
44
|
executables: []
|
@@ -49,11 +49,13 @@ files:
|
|
49
49
|
- lib/activejob-status/progress.rb
|
50
50
|
- lib/activejob-status/status.rb
|
51
51
|
- lib/activejob-status/storage.rb
|
52
|
+
- lib/activejob-status/throttle.rb
|
52
53
|
- lib/activejob-status/version.rb
|
53
|
-
homepage:
|
54
|
-
licenses:
|
54
|
+
homepage: https://github.com/inkstak/activejob-status
|
55
|
+
licenses:
|
56
|
+
- MIT
|
55
57
|
metadata: {}
|
56
|
-
post_install_message:
|
58
|
+
post_install_message:
|
57
59
|
rdoc_options: []
|
58
60
|
require_paths:
|
59
61
|
- lib
|
@@ -68,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
70
|
- !ruby/object:Gem::Version
|
69
71
|
version: '0'
|
70
72
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
73
|
+
rubygems_version: 3.2.3
|
74
|
+
signing_key:
|
74
75
|
specification_version: 4
|
75
76
|
summary: Monitor your jobs
|
76
77
|
test_files: []
|