activejob 6.0.6.1 → 6.1.7.3
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/CHANGELOG.md +103 -150
- data/MIT-LICENSE +1 -2
- data/README.md +1 -3
- data/lib/active_job/base.rb +3 -0
- data/lib/active_job/callbacks.rb +44 -4
- data/lib/active_job/core.rb +2 -2
- data/lib/active_job/enqueuing.rb +3 -13
- data/lib/active_job/exceptions.rb +29 -20
- data/lib/active_job/execution.rb +9 -1
- data/lib/active_job/gem_version.rb +3 -3
- data/lib/active_job/instrumentation.rb +40 -0
- data/lib/active_job/log_subscriber.rb +140 -0
- data/lib/active_job/logging.rb +3 -132
- data/lib/active_job/queue_adapter.rb +4 -1
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/test_adapter.rb +6 -2
- data/lib/active_job/queue_adapters.rb +5 -1
- data/lib/active_job/queue_name.rb +2 -2
- data/lib/active_job/railtie.rb +4 -0
- data/lib/active_job/serializers/date_time_serializer.rb +1 -5
- data/lib/active_job/serializers/module_serializer.rb +20 -0
- data/lib/active_job/serializers/object_serializer.rb +1 -1
- data/lib/active_job/serializers/time_object_serializer.rb +13 -0
- data/lib/active_job/serializers/time_serializer.rb +1 -5
- data/lib/active_job/serializers/time_with_zone_serializer.rb +1 -5
- data/lib/active_job/serializers.rb +4 -1
- data/lib/active_job/test_helper.rb +82 -80
- data/lib/active_job.rb +1 -1
- metadata +11 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85ce245c5553d2343a6e469717d4a84b342aa3c1c0dd0e7fe0b4509a5a7be131
|
|
4
|
+
data.tar.gz: a5ef6ed3927052ae1bccd43106bd769ec79596692d9c8b9df4728664d1e60c06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8eea01af6f2afa6664ce8d0bfcf4fdbe4c430a53574a78b083c97b9534b8c9fa0ab5315f00c882e634cb61b5d8b02cc6c341c26dd99db0c7436221de42f91d0
|
|
7
|
+
data.tar.gz: 1933dde39c56c043ead219379d96217c70f92f7ba7af394911984b26f1b59b3f611129dbfbfe0c5266559af6b3c994ea0b33b247eded66b9bd782e2f7db26aa4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,293 +1,246 @@
|
|
|
1
|
-
## Rails 6.
|
|
1
|
+
## Rails 6.1.7.3 (March 13, 2023) ##
|
|
2
2
|
|
|
3
3
|
* No changes.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
## Rails 6.
|
|
6
|
+
## Rails 6.1.7.2 (January 24, 2023) ##
|
|
7
7
|
|
|
8
8
|
* No changes.
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
## Rails 6.
|
|
11
|
+
## Rails 6.1.7.1 (January 17, 2023) ##
|
|
12
12
|
|
|
13
13
|
* No changes.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
## Rails 6.
|
|
16
|
+
## Rails 6.1.7 (September 09, 2022) ##
|
|
17
17
|
|
|
18
18
|
* No changes.
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
## Rails 6.
|
|
21
|
+
## Rails 6.1.6.1 (July 12, 2022) ##
|
|
22
22
|
|
|
23
23
|
* No changes.
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
## Rails 6.
|
|
26
|
+
## Rails 6.1.6 (May 09, 2022) ##
|
|
27
27
|
|
|
28
28
|
* No changes.
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
## Rails 6.
|
|
31
|
+
## Rails 6.1.5.1 (April 26, 2022) ##
|
|
32
32
|
|
|
33
33
|
* No changes.
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
## Rails 6.
|
|
36
|
+
## Rails 6.1.5 (March 09, 2022) ##
|
|
37
37
|
|
|
38
38
|
* No changes.
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
## Rails 6.
|
|
41
|
+
## Rails 6.1.4.7 (March 08, 2022) ##
|
|
42
42
|
|
|
43
43
|
* No changes.
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
## Rails 6.
|
|
46
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
|
47
47
|
|
|
48
48
|
* No changes.
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
## Rails 6.
|
|
51
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
|
52
52
|
|
|
53
53
|
* No changes.
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
## Rails 6.
|
|
56
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
|
57
57
|
|
|
58
58
|
* No changes.
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
## Rails 6.
|
|
61
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
|
62
62
|
|
|
63
63
|
* No changes.
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
## Rails 6.
|
|
66
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
|
67
67
|
|
|
68
68
|
* No changes.
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
## Rails 6.
|
|
71
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
|
72
72
|
|
|
73
73
|
* No changes.
|
|
74
74
|
|
|
75
75
|
|
|
76
|
-
## Rails 6.
|
|
76
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
|
77
77
|
|
|
78
78
|
* No changes.
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
## Rails 6.
|
|
81
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
|
82
82
|
|
|
83
83
|
* No changes.
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
## Rails 6.
|
|
86
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
|
87
87
|
|
|
88
88
|
* No changes.
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
## Rails 6.
|
|
91
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
|
92
92
|
|
|
93
93
|
* No changes.
|
|
94
94
|
|
|
95
95
|
|
|
96
|
-
## Rails 6.
|
|
96
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
|
97
97
|
|
|
98
98
|
* No changes.
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
## Rails 6.
|
|
102
|
-
|
|
103
|
-
* While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
|
|
104
|
-
`assert_enqueued_with`.
|
|
105
|
-
|
|
106
|
-
*Dmitry Polushkin*
|
|
107
|
-
|
|
108
|
-
* Add queue name support to Que adapter
|
|
109
|
-
|
|
110
|
-
*Brad Nauta*, *Wojciech Wnętrzak*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
## Rails 6.0.2.2 (March 19, 2020) ##
|
|
101
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
|
114
102
|
|
|
115
103
|
* No changes.
|
|
116
104
|
|
|
117
105
|
|
|
118
|
-
## Rails 6.
|
|
106
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
|
119
107
|
|
|
120
|
-
*
|
|
108
|
+
* Make `retry_job` return the job that was created.
|
|
121
109
|
|
|
110
|
+
*Rafael Mendonça França*
|
|
122
111
|
|
|
123
|
-
|
|
112
|
+
* Include `ActiveSupport::Testing::Assertions` in `ActiveJob::TestHelpers`.
|
|
124
113
|
|
|
125
|
-
*
|
|
114
|
+
*Mikkel Malmberg*
|
|
126
115
|
|
|
127
|
-
By having access to the Active Job class, Sidekiq can get access to any `sidekiq_options` which
|
|
128
|
-
have been set on that Active Job type and serialize those options into Redis.
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
|
131
118
|
|
|
132
|
-
|
|
119
|
+
* Recover nano precision when serializing `Time`, `TimeWithZone` and `DateTime` objects.
|
|
133
120
|
|
|
121
|
+
*Alan Tan*
|
|
134
122
|
|
|
135
|
-
|
|
123
|
+
* Deprecate `config.active_job.return_false_on_aborted_enqueue`.
|
|
136
124
|
|
|
137
|
-
*
|
|
125
|
+
*Rafael Mendonça França*
|
|
138
126
|
|
|
127
|
+
* Return `false` when enqueuing a job is aborted.
|
|
139
128
|
|
|
140
|
-
|
|
129
|
+
*Rafael Mendonça França*
|
|
141
130
|
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
*Vlado Cingel*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
|
148
|
-
|
|
149
|
-
* No changes.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
|
153
|
-
|
|
154
|
-
* Use individual execution counters when calculating retry delay.
|
|
155
|
-
|
|
156
|
-
*Patrik Bóna*
|
|
157
|
-
|
|
158
|
-
* Make job argument assertions with `Time`, `ActiveSupport::TimeWithZone`, and `DateTime` work by dropping microseconds. Microsecond precision is lost during serialization.
|
|
159
|
-
|
|
160
|
-
*Gannon McGibbon*
|
|
131
|
+
* While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
|
|
132
|
+
`assert_enqueued_with`.
|
|
161
133
|
|
|
134
|
+
*Dmitry Polushkin*
|
|
162
135
|
|
|
163
|
-
|
|
136
|
+
* `ActiveJob::TestCase#perform_enqueued_jobs` without a block removes performed jobs from the queue.
|
|
164
137
|
|
|
165
|
-
|
|
138
|
+
That way the helper can be called multiple times and not perform a job invocation multiple times.
|
|
166
139
|
|
|
140
|
+
```ruby
|
|
141
|
+
def test_jobs
|
|
142
|
+
HelloJob.perform_later("rafael")
|
|
143
|
+
perform_enqueued_jobs # only runs with "rafael"
|
|
144
|
+
HelloJob.perform_later("david")
|
|
145
|
+
perform_enqueued_jobs # only runs with "david"
|
|
146
|
+
end
|
|
147
|
+
```
|
|
167
148
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
* No changes.
|
|
149
|
+
*Étienne Barrié*
|
|
171
150
|
|
|
151
|
+
* `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
|
|
172
152
|
|
|
173
|
-
|
|
153
|
+
When calling `perform_enqueued_jobs` without a block, the adapter will
|
|
154
|
+
now perform jobs that are **already** in the queue. Jobs that will end up in
|
|
155
|
+
the queue afterwards won't be performed.
|
|
174
156
|
|
|
175
|
-
|
|
157
|
+
This change only affects `perform_enqueued_jobs` when no block is given.
|
|
176
158
|
|
|
177
|
-
|
|
178
|
-
`config.active_job.return_false_on_aborted_enqueue`.
|
|
159
|
+
*Edouard Chin*
|
|
179
160
|
|
|
180
|
-
|
|
161
|
+
* Add queue name support to Que adapter.
|
|
181
162
|
|
|
182
|
-
*
|
|
163
|
+
*Brad Nauta*, *Wojciech Wnętrzak*
|
|
183
164
|
|
|
184
|
-
|
|
185
|
-
shared between all executions of a job.
|
|
165
|
+
* Don't run `after_enqueue` and `after_perform` callbacks if the callback chain is halted.
|
|
186
166
|
|
|
187
|
-
|
|
167
|
+
class MyJob < ApplicationJob
|
|
168
|
+
before_enqueue { throw(:abort) }
|
|
169
|
+
after_enqueue { # won't enter here anymore }
|
|
170
|
+
end
|
|
188
171
|
|
|
189
|
-
|
|
190
|
-
|
|
172
|
+
`after_enqueue` and `after_perform` callbacks will no longer run if the callback chain is halted.
|
|
173
|
+
This behaviour is a breaking change and won't take effect until Rails 7.0.
|
|
174
|
+
To enable this behaviour in your app right now, you can add in your app's configuration file
|
|
175
|
+
`config.active_job.skip_after_callbacks_if_terminated = true`.
|
|
191
176
|
|
|
192
177
|
*Edouard Chin*
|
|
193
178
|
|
|
194
|
-
*
|
|
179
|
+
* Fix enqueuing and performing incorrect logging message.
|
|
195
180
|
|
|
196
|
-
|
|
181
|
+
Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
|
|
197
182
|
|
|
198
|
-
|
|
199
|
-
|
|
183
|
+
```ruby
|
|
184
|
+
class MyJob < ApplicationJob
|
|
185
|
+
before_enqueue { throw(:abort) }
|
|
186
|
+
end
|
|
200
187
|
|
|
201
|
-
|
|
188
|
+
MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.
|
|
189
|
+
```
|
|
202
190
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
matches your expectations.
|
|
191
|
+
A new message will be logged in case a job couldn't be enqueued, either because the callback chain was halted or
|
|
192
|
+
because an exception happened during enqueuing. (i.e. Redis is down when you try to enqueue your job)
|
|
206
193
|
|
|
207
194
|
*Edouard Chin*
|
|
208
195
|
|
|
209
|
-
*
|
|
196
|
+
* Add an option to disable logging of the job arguments when enqueuing and executing the job.
|
|
210
197
|
|
|
211
|
-
|
|
198
|
+
class SensitiveJob < ApplicationJob
|
|
199
|
+
self.log_arguments = false
|
|
212
200
|
|
|
213
|
-
|
|
201
|
+
def perform(my_sensitive_argument)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
214
204
|
|
|
215
|
-
|
|
205
|
+
When dealing with sensitive arguments as password and tokens it is now possible to configure the job
|
|
206
|
+
to not put the sensitive argument in the logs.
|
|
216
207
|
|
|
217
|
-
*
|
|
208
|
+
*Rafael Mendonça França*
|
|
218
209
|
|
|
219
|
-
|
|
210
|
+
* Changes in `queue_name_prefix` of a job no longer affects all other jobs.
|
|
220
211
|
|
|
221
|
-
|
|
222
|
-
without a block should respect passed `:except`, `:only`, and `:queue` options.
|
|
212
|
+
Fixes #37084.
|
|
223
213
|
|
|
224
|
-
*
|
|
214
|
+
*Lucas Mansur*
|
|
225
215
|
|
|
226
|
-
* Allow
|
|
227
|
-
|
|
228
|
-
*bogdanvlviv*
|
|
229
|
-
|
|
230
|
-
* Allow `perform_enqueued_jobs` to be called without a block.
|
|
231
|
-
|
|
232
|
-
Performs all of the jobs that have been enqueued up to this point in the test.
|
|
216
|
+
* Allow `Class` and `Module` instances to be serialized.
|
|
233
217
|
|
|
234
218
|
*Kevin Deisz*
|
|
235
219
|
|
|
236
|
-
*
|
|
237
|
-
|
|
238
|
-
Improves timing accuracy over the old after callback by including
|
|
239
|
-
time spent writing to the adapter's IO implementation.
|
|
240
|
-
|
|
241
|
-
*Zach Kemp*
|
|
242
|
-
|
|
243
|
-
* Allow call `assert_enqueued_with` with no block.
|
|
244
|
-
|
|
245
|
-
Example:
|
|
246
|
-
```
|
|
247
|
-
def test_assert_enqueued_with
|
|
248
|
-
MyJob.perform_later(1,2,3)
|
|
249
|
-
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
|
|
250
|
-
|
|
251
|
-
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
252
|
-
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
|
|
253
|
-
end
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
*bogdanvlviv*
|
|
257
|
-
|
|
258
|
-
* Allow passing multiple exceptions to `retry_on`, and `discard_on`.
|
|
259
|
-
|
|
260
|
-
*George Claghorn*
|
|
220
|
+
* Log potential matches in `assert_enqueued_with` and `assert_performed_with`.
|
|
261
221
|
|
|
262
|
-
*
|
|
222
|
+
*Gareth du Plooy*
|
|
263
223
|
|
|
264
|
-
|
|
224
|
+
* Add `at` argument to the `perform_enqueued_jobs` test helper.
|
|
265
225
|
|
|
266
|
-
*
|
|
226
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
|
267
227
|
|
|
268
|
-
*
|
|
269
|
-
|
|
270
|
-
Reasons are that the Qu gem wasn't compatible since Rails 5.1,
|
|
271
|
-
gem development was stopped in 2014 and maintainers have
|
|
272
|
-
confirmed its demise. See issue #32273
|
|
273
|
-
|
|
274
|
-
*Alberto Almagro*
|
|
275
|
-
|
|
276
|
-
* Add support for timezones to Active Job.
|
|
277
|
-
|
|
278
|
-
Record what was the current timezone in effect when the job was
|
|
279
|
-
enqueued and then restore when the job is executed in same way
|
|
280
|
-
that the current locale is recorded and restored.
|
|
228
|
+
* `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
|
|
281
229
|
|
|
282
|
-
*
|
|
230
|
+
*Vlado Cingel*
|
|
283
231
|
|
|
284
|
-
*
|
|
232
|
+
* Add jitter to `ActiveJob::Exceptions.retry_on`.
|
|
285
233
|
|
|
286
|
-
|
|
234
|
+
`ActiveJob::Exceptions.retry_on` now uses a random amount of jitter in order to
|
|
235
|
+
prevent the [thundering herd effect](https://en.wikipedia.org/wiki/Thundering_herd_problem). Defaults to
|
|
236
|
+
15% (represented as 0.15) but overridable via the `:jitter` option when using `retry_on`.
|
|
237
|
+
Jitter is applied when an `Integer`, `ActiveSupport::Duration` or `:exponentially_longer`, is passed to the `wait` argument in `retry_on`.
|
|
287
238
|
|
|
288
|
-
|
|
239
|
+
```ruby
|
|
240
|
+
retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)
|
|
241
|
+
```
|
|
289
242
|
|
|
290
|
-
*
|
|
243
|
+
*Anthony Ross*
|
|
291
244
|
|
|
292
245
|
|
|
293
|
-
Please check [
|
|
246
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activejob/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2014-
|
|
1
|
+
Copyright (c) 2014-2022 David Heinemeier Hansson
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
|
@@ -18,4 +18,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
-
|
data/README.md
CHANGED
|
@@ -95,9 +95,6 @@ their gem, or as a stand-alone gem. For discussion about this see the
|
|
|
95
95
|
following PRs: [23311](https://github.com/rails/rails/issues/23311#issuecomment-176275718),
|
|
96
96
|
[21406](https://github.com/rails/rails/pull/21406#issuecomment-138813484), and [#32285](https://github.com/rails/rails/pull/32285).
|
|
97
97
|
|
|
98
|
-
## Auxiliary gems
|
|
99
|
-
|
|
100
|
-
* [activejob-stats](https://github.com/seuros/activejob-stats)
|
|
101
98
|
|
|
102
99
|
## Download and installation
|
|
103
100
|
|
|
@@ -111,6 +108,7 @@ Source code can be downloaded as part of the Rails project on GitHub:
|
|
|
111
108
|
|
|
112
109
|
* https://github.com/rails/rails/tree/main/activejob
|
|
113
110
|
|
|
111
|
+
|
|
114
112
|
## License
|
|
115
113
|
|
|
116
114
|
Active Job is released under the MIT license:
|
data/lib/active_job/base.rb
CHANGED
|
@@ -8,7 +8,9 @@ require "active_job/enqueuing"
|
|
|
8
8
|
require "active_job/execution"
|
|
9
9
|
require "active_job/callbacks"
|
|
10
10
|
require "active_job/exceptions"
|
|
11
|
+
require "active_job/log_subscriber"
|
|
11
12
|
require "active_job/logging"
|
|
13
|
+
require "active_job/instrumentation"
|
|
12
14
|
require "active_job/timezones"
|
|
13
15
|
require "active_job/translation"
|
|
14
16
|
|
|
@@ -68,6 +70,7 @@ module ActiveJob #:nodoc:
|
|
|
68
70
|
include Callbacks
|
|
69
71
|
include Exceptions
|
|
70
72
|
include Logging
|
|
73
|
+
include Instrumentation
|
|
71
74
|
include Timezones
|
|
72
75
|
include Translation
|
|
73
76
|
|
data/lib/active_job/callbacks.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_support/callbacks"
|
|
4
|
+
require "active_support/core_ext/object/with_options"
|
|
5
|
+
require "active_support/core_ext/module/attribute_accessors"
|
|
4
6
|
|
|
5
7
|
module ActiveJob
|
|
6
8
|
# = Active Job Callbacks
|
|
@@ -27,16 +29,25 @@ module ActiveJob
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
included do
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false, default: false
|
|
33
|
+
singleton_class.deprecate :return_false_on_aborted_enqueue, :return_false_on_aborted_enqueue=
|
|
34
|
+
cattr_accessor :skip_after_callbacks_if_terminated, instance_accessor: false, default: false
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
with_options(skip_after_callbacks_if_terminated: skip_after_callbacks_if_terminated) do
|
|
37
|
+
define_callbacks :perform
|
|
38
|
+
define_callbacks :enqueue
|
|
39
|
+
end
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
# These methods will be included into any Active Job object, adding
|
|
38
43
|
# callbacks for +perform+ and +enqueue+ methods.
|
|
39
44
|
module ClassMethods
|
|
45
|
+
def inherited(klass)
|
|
46
|
+
klass.get_callbacks(:enqueue).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated
|
|
47
|
+
klass.get_callbacks(:perform).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated
|
|
48
|
+
super
|
|
49
|
+
end
|
|
50
|
+
|
|
40
51
|
# Defines a callback that will get called right before the
|
|
41
52
|
# job's perform method is executed.
|
|
42
53
|
#
|
|
@@ -91,6 +102,19 @@ module ActiveJob
|
|
|
91
102
|
# end
|
|
92
103
|
# end
|
|
93
104
|
#
|
|
105
|
+
# You can access the return value of the job only if the execution wasn't halted.
|
|
106
|
+
#
|
|
107
|
+
# class VideoProcessJob < ActiveJob::Base
|
|
108
|
+
# around_perform do |job, block|
|
|
109
|
+
# value = block.call
|
|
110
|
+
# puts value # => "Hello World!"
|
|
111
|
+
# end
|
|
112
|
+
#
|
|
113
|
+
# def perform
|
|
114
|
+
# "Hello World!"
|
|
115
|
+
# end
|
|
116
|
+
# end
|
|
117
|
+
#
|
|
94
118
|
def around_perform(*filters, &blk)
|
|
95
119
|
set_callback(:perform, :around, *filters, &blk)
|
|
96
120
|
end
|
|
@@ -154,5 +178,21 @@ module ActiveJob
|
|
|
154
178
|
set_callback(:enqueue, :around, *filters, &blk)
|
|
155
179
|
end
|
|
156
180
|
end
|
|
181
|
+
|
|
182
|
+
private
|
|
183
|
+
def halted_callback_hook(_filter, name) # :nodoc:
|
|
184
|
+
return super unless %i(enqueue perform).include?(name.to_sym)
|
|
185
|
+
callbacks = public_send("_#{name}_callbacks")
|
|
186
|
+
|
|
187
|
+
if !self.class.skip_after_callbacks_if_terminated && callbacks.any? { |c| c.kind == :after }
|
|
188
|
+
ActiveSupport::Deprecation.warn(<<~EOM)
|
|
189
|
+
In Rails 7.0, `after_enqueue`/`after_perform` callbacks no longer run if `before_enqueue`/`before_perform` respectively halts with `throw :abort`.
|
|
190
|
+
To enable this behavior, uncomment the `config.active_job.skip_after_callbacks_if_terminated` config
|
|
191
|
+
in the new 6.1 framework defaults initializer.
|
|
192
|
+
EOM
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
super
|
|
196
|
+
end
|
|
157
197
|
end
|
|
158
198
|
end
|
data/lib/active_job/core.rb
CHANGED
|
@@ -85,7 +85,7 @@ module ActiveJob
|
|
|
85
85
|
@priority = self.class.priority
|
|
86
86
|
@executions = 0
|
|
87
87
|
@exception_executions = {}
|
|
88
|
-
@timezone = Time.zone
|
|
88
|
+
@timezone = Time.zone&.name
|
|
89
89
|
end
|
|
90
90
|
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
|
91
91
|
|
|
@@ -142,7 +142,7 @@ module ActiveJob
|
|
|
142
142
|
self.executions = job_data["executions"]
|
|
143
143
|
self.exception_executions = job_data["exception_executions"]
|
|
144
144
|
self.locale = job_data["locale"] || I18n.locale.to_s
|
|
145
|
-
self.timezone = job_data["timezone"] || Time.zone
|
|
145
|
+
self.timezone = job_data["timezone"] || Time.zone&.name
|
|
146
146
|
self.enqueued_at = job_data["enqueued_at"]
|
|
147
147
|
end
|
|
148
148
|
|
data/lib/active_job/enqueuing.rb
CHANGED
|
@@ -54,9 +54,9 @@ module ActiveJob
|
|
|
54
54
|
|
|
55
55
|
run_callbacks :enqueue do
|
|
56
56
|
if scheduled_at
|
|
57
|
-
|
|
57
|
+
queue_adapter.enqueue_at self, scheduled_at
|
|
58
58
|
else
|
|
59
|
-
|
|
59
|
+
queue_adapter.enqueue self
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
successfully_enqueued = true
|
|
@@ -65,17 +65,7 @@ module ActiveJob
|
|
|
65
65
|
if successfully_enqueued
|
|
66
66
|
self
|
|
67
67
|
else
|
|
68
|
-
|
|
69
|
-
false
|
|
70
|
-
else
|
|
71
|
-
ActiveSupport::Deprecation.warn(
|
|
72
|
-
"Rails 6.1 will return false when the enqueuing is aborted. Make sure your code doesn't depend on it" \
|
|
73
|
-
" returning the instance of the job and set `config.active_job.return_false_on_aborted_enqueue = true`" \
|
|
74
|
-
" to remove the deprecations."
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
self
|
|
78
|
-
end
|
|
68
|
+
false
|
|
79
69
|
end
|
|
80
70
|
end
|
|
81
71
|
end
|