activejob-status 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f631add9a816c630d494258c0c62b8357f04d6cf1dcb4c8681646f294b1af1e
4
- data.tar.gz: 1bf02e33cfc7ae8e5ffddfd72466efd181d241cab6cfa1a07b75094fd241c18c
3
+ metadata.gz: caa59f53f6175aea2f38a219adfd4a707fc3fb8460265aeff78adc7b09a494f2
4
+ data.tar.gz: f8775e045b684ba6cc1215e2e7570ba8e7b4f10ad889d7fb5d78bea44a5b62f1
5
5
  SHA512:
6
- metadata.gz: 71af5a019d4004e27400abc14ee1b3d5c83a794d86096f0dd821a5f8fd52782b303beaac6b31533b6b50e74e44c2254d7e9bbed52d3439556f79aff6fa349ad9
7
- data.tar.gz: b5ab17ba47d02f4a0493fc92b34684b261c1720da1da18627a050a7746129febdbcc30e750970d356948b738ab306a4fc8cecb2ca7dc35ccbf1a9c477a46dea8
6
+ metadata.gz: a15529aeaab2bf3e25a5a56fab998e867f9af6fd3f835b788a84f001f9f4be4f974c8e7e2d3d40f8f45b6d764b40984af69a11cc95c9edece1e6e987c8e5dee8
7
+ data.tar.gz: 48fa3e3ee20a768007b830b5f5019d958594c4ec26ffd8d0bdb8bcd7d0dbdbd8d6da63408df591bda657b5de93bc991f08f84b7b8076cf699ed86385671d72e2
@@ -8,7 +8,8 @@ module ActiveJob
8
8
 
9
9
  def initialize(job, options = {})
10
10
  options = ActiveJob::Status.options.merge(options)
11
- @storage = ActiveJob::Status::Storage.new(options)
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,11 @@ module ActiveJob
21
22
  end
22
23
  alias_method :to_h, :read
23
24
 
24
- def update(message, options = {})
25
- @job.progress.instance_variable_set(:@progress, message[:progress]) if message.include?(:progress)
26
- @job.progress.instance_variable_set(:@total, message[:total]) if message.include?(:total)
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)
27
28
 
28
- @storage.update(@job, message, **options)
29
+ @storage.update(@job, payload, **options)
29
30
  end
30
31
 
31
32
  def delete
@@ -51,6 +52,23 @@ module ActiveJob
51
52
  def status_inquiry
52
53
  status.to_s.inquiry
53
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
54
72
  end
55
73
  end
56
74
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module Status
5
- VERSION = "0.2.2"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -13,16 +13,17 @@ module ActiveJob
13
13
 
14
14
  DEFAULT_OPTIONS = {
15
15
  expires_in: 60 * 30,
16
- throttle_interval: 0
16
+ throttle_interval: 0,
17
+ includes: %i[status]
17
18
  }.freeze
18
19
 
19
20
  included do
20
- before_enqueue { |job| job.status[:status] = :queued }
21
- before_perform { |job| job.status[:status] = :working }
22
- after_perform { |job| job.status[:status] = :completed }
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) }
23
24
 
24
25
  rescue_from(Exception) do |e|
25
- status[:status] = :failed
26
+ status.catch_exception(e)
26
27
  raise e
27
28
  end
28
29
  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.2.2
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: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2022-11-02 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.1.4
73
+ rubygems_version: 3.3.7
186
74
  signing_key:
187
75
  specification_version: 4
188
76
  summary: Monitor your jobs