activejob-status 0.2.2 → 0.4.0
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/status.rb +29 -5
- data/lib/activejob-status/version.rb +1 -1
- data/lib/activejob-status.rb +8 -5
- metadata +3 -115
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c7fee3b739316143dadbbc360b14c1557c30e6a83199d606675d4eb5164f7b
|
4
|
+
data.tar.gz: eef77191de849b3f4a063569a0b9016c55fb1c94b3c1856d8ed89e69bedb9631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bf621c0950c2c55e03d8aca6ffd38e327d0ae4afd5a55d130af80c02e4d81a5dc4557133dd7dd4ee394113ba3e3ebfc831feb268aee2fdc7caef9d2fde6d9b6
|
7
|
+
data.tar.gz: d0a5aac3bf768f3c17f396dc09c6386364bea3291862ca6144df032c5d7aacdae0a351347e86ff480dde17d322ad9353e19f64664280a9d27d7503d3aa5e2918
|
@@ -8,7 +8,8 @@ module ActiveJob
|
|
8
8
|
|
9
9
|
def initialize(job, options = {})
|
10
10
|
options = ActiveJob::Status.options.merge(options)
|
11
|
-
@
|
11
|
+
@defaults = options.fetch(:includes, [])
|
12
|
+
@storage = ActiveJob::Status::Storage.new(options.without(:includes))
|
12
13
|
@job = job
|
13
14
|
end
|
14
15
|
|
@@ -21,11 +22,13 @@ module ActiveJob
|
|
21
22
|
end
|
22
23
|
alias_method :to_h, :read
|
23
24
|
|
24
|
-
def update(
|
25
|
-
@job.
|
26
|
-
|
25
|
+
def update(payload, options = {})
|
26
|
+
if @job.respond_to?(:progress)
|
27
|
+
@job.progress.instance_variable_set(:@progress, payload[:progress]) if payload.include?(:progress)
|
28
|
+
@job.progress.instance_variable_set(:@total, payload[:total]) if payload.include?(:total)
|
29
|
+
end
|
27
30
|
|
28
|
-
@storage.update(@job,
|
31
|
+
@storage.update(@job, payload, **options)
|
29
32
|
end
|
30
33
|
|
31
34
|
def delete
|
@@ -51,6 +54,27 @@ module ActiveJob
|
|
51
54
|
def status_inquiry
|
52
55
|
status.to_s.inquiry
|
53
56
|
end
|
57
|
+
|
58
|
+
# Update default data
|
59
|
+
|
60
|
+
def update_defaults(status_key)
|
61
|
+
raise "cannot call #update_defaults when status is accessed from outside the job" if @job.is_a?(String)
|
62
|
+
|
63
|
+
payload = {}
|
64
|
+
payload[:status] = status_key if @defaults.include?(:status)
|
65
|
+
payload[:serialized_job] = @job.serialize if @defaults.include?(:serialized_job)
|
66
|
+
update(payload, force: true)
|
67
|
+
end
|
68
|
+
|
69
|
+
def catch_exception(e)
|
70
|
+
raise "cannot call #catch_exception when status is accessed from outside the job" if @job.is_a?(String)
|
71
|
+
|
72
|
+
payload = {}
|
73
|
+
payload[:status] = :failed if @defaults.include?(:status)
|
74
|
+
payload[:serialized_job] = @job.serialize if @defaults.include?(:serialized_job)
|
75
|
+
payload[:exception] = {class: e.class.name, message: e.original_message} if @defaults.include?(:exception)
|
76
|
+
update(payload, force: true)
|
77
|
+
end
|
54
78
|
end
|
55
79
|
end
|
56
80
|
end
|
data/lib/activejob-status.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
4
|
require "active_support/core_ext/hash"
|
5
|
+
require "active_support/core_ext/enumerable"
|
6
|
+
require "active_job"
|
5
7
|
require "activejob-status/storage"
|
6
8
|
require "activejob-status/status"
|
7
9
|
require "activejob-status/progress"
|
@@ -13,16 +15,17 @@ module ActiveJob
|
|
13
15
|
|
14
16
|
DEFAULT_OPTIONS = {
|
15
17
|
expires_in: 60 * 30,
|
16
|
-
throttle_interval: 0
|
18
|
+
throttle_interval: 0,
|
19
|
+
includes: %i[status]
|
17
20
|
}.freeze
|
18
21
|
|
19
22
|
included do
|
20
|
-
before_enqueue { |job| job.status
|
21
|
-
before_perform { |job| job.status
|
22
|
-
after_perform { |job| job.status
|
23
|
+
before_enqueue { |job| job.status.update_defaults(:queued) }
|
24
|
+
before_perform { |job| job.status.update_defaults(:working) }
|
25
|
+
after_perform { |job| job.status.update_defaults(:completed) }
|
23
26
|
|
24
27
|
rescue_from(Exception) do |e|
|
25
|
-
status
|
28
|
+
status.catch_exception(e)
|
26
29
|
raise e
|
27
30
|
end
|
28
31
|
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.
|
4
|
+
version: 0.4.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-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -38,118 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.2'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bundler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.3'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.3'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.20'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.20'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-performance
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.11'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.11'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rubocop-rspec
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '2.4'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '2.4'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-rake
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: standard
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 1.3.0
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 1.3.0
|
153
41
|
description:
|
154
42
|
email:
|
155
43
|
- savater.sebastien@gmail.com
|
@@ -182,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
70
|
- !ruby/object:Gem::Version
|
183
71
|
version: '0'
|
184
72
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.3.7
|
186
74
|
signing_key:
|
187
75
|
specification_version: 4
|
188
76
|
summary: Monitor your jobs
|