activejob 7.0.8 → 7.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +128 -150
- data/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/lib/active_job/arguments.rb +14 -25
- data/lib/active_job/base.rb +1 -1
- data/lib/active_job/callbacks.rb +1 -4
- data/lib/active_job/configured_job.rb +4 -0
- data/lib/active_job/core.rb +26 -6
- data/lib/active_job/deprecator.rb +7 -0
- data/lib/active_job/enqueuing.rb +31 -1
- data/lib/active_job/exceptions.rb +42 -5
- data/lib/active_job/execution.rb +5 -1
- data/lib/active_job/gem_version.rb +4 -4
- data/lib/active_job/instrumentation.rb +18 -10
- data/lib/active_job/log_subscriber.rb +78 -8
- data/lib/active_job/queue_adapter.rb +13 -2
- data/lib/active_job/queue_adapters/async_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/backburner_adapter.rb +7 -3
- data/lib/active_job/queue_adapters/delayed_job_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/queue_classic_adapter.rb +4 -4
- data/lib/active_job/queue_adapters/resque_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +42 -14
- data/lib/active_job/queue_adapters/sneakers_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/test_adapter.rb +3 -3
- data/lib/active_job/queue_adapters.rb +8 -7
- data/lib/active_job/queue_priority.rb +18 -1
- data/lib/active_job/railtie.rb +25 -6
- data/lib/active_job/serializers/big_decimal_serializer.rb +22 -0
- data/lib/active_job/serializers/duration_serializer.rb +4 -2
- data/lib/active_job/serializers.rb +7 -3
- data/lib/active_job/test_helper.rb +23 -3
- data/lib/active_job/version.rb +1 -1
- data/lib/active_job.rb +26 -4
- data/lib/rails/generators/job/USAGE +19 -0
- data/lib/rails/generators/job/job_generator.rb +6 -2
- data/lib/rails/generators/job/templates/job.rb.tt +1 -1
- metadata +12 -10
- data/lib/active_job/queue_adapters/que_adapter.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6afc607e83451a80e5538b8289eb78a3d4256a82648d2fc364c00b35d86652a1
|
4
|
+
data.tar.gz: 66372474efc76dc1bcb4e4bc7e32bc6ccfbf62242bd394bfa0b6982a65a48133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ec6a49ca490b307c258df58fa5d6885d7be0ecd3d7db615096a06696ea718e129002198603cd46be21a3c2c7e43146e22e0f3350da69c3a828945a3785cff8
|
7
|
+
data.tar.gz: 1d051b0f106d489def667bf37f5801a452269742c25029fd392eb826a02830762730bae3fb556f8a175b79f91b57bb43e49c6d1f69d74ed4d40edea03abe2c1f
|
data/CHANGELOG.md
CHANGED
@@ -1,116 +1,194 @@
|
|
1
|
-
## Rails 7.0.
|
1
|
+
## Rails 7.1.0.rc1 (September 27, 2023) ##
|
2
|
+
|
3
|
+
* Set `scheduled_at` attribute as a Time object instead of epoch seconds, and serialize and deserialize the value
|
4
|
+
when enqueued. Assigning a numeric/epoch value to scheduled_at= is deprecated; use a Time object instead.
|
5
|
+
|
6
|
+
Deserializes `enqueued_at` as a Time instead of ISO8601 String.
|
7
|
+
|
8
|
+
*Ben Sheldon*
|
9
|
+
|
10
|
+
* Clarify the backoff strategy for the recommended `:wait` option when retrying jobs
|
11
|
+
|
12
|
+
`wait: :exponentially_longer` is waiting polynomially longer, so it is now recommended to use `wait: :polynomially_longer` to keep the same behavior.
|
13
|
+
|
14
|
+
*Victor Mours*
|
15
|
+
|
16
|
+
|
17
|
+
## Rails 7.1.0.beta1 (September 13, 2023) ##
|
2
18
|
|
3
19
|
* Fix Active Job log message to correctly report a job failed to enqueue
|
4
20
|
when the adapter raises an `ActiveJob::EnqueueError`.
|
5
21
|
|
6
22
|
*Ben Sheldon*
|
7
23
|
|
24
|
+
* Add `after_discard` method.
|
8
25
|
|
9
|
-
|
26
|
+
This method lets job authors define a block which will be run when a job is about to be discarded. For example:
|
10
27
|
|
11
|
-
|
28
|
+
```ruby
|
29
|
+
class AfterDiscardJob < ActiveJob::Base
|
30
|
+
after_discard do |job, exception|
|
31
|
+
Rails.logger.info("#{job.class} raised an exception: #{exception}")
|
32
|
+
end
|
12
33
|
|
34
|
+
def perform
|
35
|
+
raise StandardError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
13
39
|
|
14
|
-
|
40
|
+
The above job will run the block passed to `after_discard` after the job is discarded. The exception will
|
41
|
+
still be raised after the block has been run.
|
15
42
|
|
16
|
-
*
|
43
|
+
*Rob Cardy*
|
17
44
|
|
45
|
+
* Fix deserialization of ActiveSupport::Duration
|
18
46
|
|
19
|
-
|
47
|
+
Previously, a deserialized Duration would return an array from Duration#parts.
|
48
|
+
It will now return a hash just like a regular Duration.
|
20
49
|
|
21
|
-
|
50
|
+
This also fixes an error when trying to add or subtract from a deserialized Duration
|
51
|
+
(eg `duration + 1.year`).
|
22
52
|
|
53
|
+
*Jonathan del Strother*
|
23
54
|
|
24
|
-
|
55
|
+
* `perform_enqueued_jobs` is now compatible with all Active Job adapters
|
25
56
|
|
26
|
-
|
57
|
+
This means that methods that depend on it, like Action Mailer's `assert_emails`,
|
58
|
+
will work correctly even if the test adapter is not used.
|
27
59
|
|
28
|
-
*Alex
|
60
|
+
*Alex Ghiculescu*
|
29
61
|
|
62
|
+
* Allow queue adapters to provide a custom name by implementing `queue_adapter_name`
|
30
63
|
|
31
|
-
|
64
|
+
*Sander Verdonschot*
|
32
65
|
|
33
|
-
*
|
66
|
+
* Log background job enqueue callers
|
34
67
|
|
68
|
+
Add `verbose_enqueue_logs` configuration option to display the caller
|
69
|
+
of background job enqueue in the log to help with debugging.
|
35
70
|
|
36
|
-
|
71
|
+
Example log line:
|
37
72
|
|
38
|
-
|
73
|
+
```
|
74
|
+
Enqueued AvatarThumbnailsJob (Job ID: ab528951-41fb-4c48-9129-3171791c27d6) to Sidekiq(default) with arguments: 1092412064
|
75
|
+
↳ app/models/user.rb:421:in `generate_avatar_thumbnails'
|
76
|
+
```
|
39
77
|
|
40
|
-
|
78
|
+
Enabled in development only for new and upgraded applications. Not recommended for use
|
79
|
+
in the production environment since it relies on Ruby's `Kernel#caller` which is fairly slow.
|
41
80
|
|
42
|
-
*
|
81
|
+
*fatkodima*
|
43
82
|
|
44
|
-
|
45
|
-
`:job`, the job name would get logged twice. This bug has been fixed.
|
83
|
+
* Set `provider_job_id` for Backburner jobs
|
46
84
|
|
47
|
-
*
|
85
|
+
*Cameron Matheson*
|
86
|
+
|
87
|
+
* Add `perform_all_later` to enqueue multiple jobs at once
|
88
|
+
|
89
|
+
This adds the ability to bulk enqueue jobs, without running callbacks, by
|
90
|
+
passing multiple jobs or an array of jobs. For example:
|
48
91
|
|
92
|
+
```ruby
|
93
|
+
ActiveJob.perform_all_later(MyJob.new("hello", 42), MyJob.new("world", 0))
|
49
94
|
|
50
|
-
|
95
|
+
user_jobs = User.pluck(:id).map { |id| UserJob.new(user_id: id) }
|
96
|
+
ActiveJob.perform_all_later(user_jobs)
|
97
|
+
```
|
51
98
|
|
52
|
-
|
99
|
+
This can greatly reduce the number of round-trips to the queue datastore.
|
100
|
+
For queue adapters that do not implement the new `enqueue_all` method, we
|
101
|
+
fall back to enqueuing jobs individually. The Sidekiq adapter implements
|
102
|
+
`enqueue_all` with `push_bulk`.
|
53
103
|
|
104
|
+
This method does not use the existing `enqueue.active_job` event, but adds a
|
105
|
+
new event `enqueue_all.active_job`.
|
54
106
|
|
55
|
-
|
107
|
+
*Sander Verdonschot*
|
56
108
|
|
57
|
-
*
|
109
|
+
* Don't double log the `job` when using `ActiveRecord::QueryLog`
|
58
110
|
|
111
|
+
Previously if you set `config.active_record.query_log_tags` to an array that included
|
112
|
+
`:job`, the job name would get logged twice. This bug has been fixed.
|
59
113
|
|
60
|
-
|
114
|
+
*Alex Ghiculescu*
|
61
115
|
|
62
|
-
*
|
116
|
+
* Add support for Sidekiq's transaction-aware client
|
63
117
|
|
118
|
+
*Jonathan del Strother*
|
64
119
|
|
65
|
-
|
120
|
+
* Remove QueAdapter from Active Job.
|
66
121
|
|
67
|
-
|
122
|
+
After maintaining Active Job QueAdapter by Rails and Que side
|
123
|
+
to support Ruby 3 keyword arguments and options provided as top level keywords,
|
124
|
+
it is quite difficult to maintain it this way.
|
68
125
|
|
69
|
-
|
70
|
-
que 2.0 necessary for Ruby 3 compatibility.
|
126
|
+
Active Job Que adapter can be included in the future version of que gem itself.
|
71
127
|
|
72
|
-
*
|
128
|
+
*Yasuo Honda*
|
73
129
|
|
74
|
-
|
130
|
+
* Fix BigDecimal (de)serialization for adapters using JSON.
|
75
131
|
|
76
|
-
|
132
|
+
Previously, BigDecimal was listed as not needing a serializer. However,
|
133
|
+
when used with an adapter storing the job arguments as JSON, it would get
|
134
|
+
serialized as a simple String, resulting in deserialization also producing
|
135
|
+
a String (instead of a BigDecimal).
|
77
136
|
|
137
|
+
By using a serializer, we ensure the round trip is safe.
|
78
138
|
|
79
|
-
|
139
|
+
To ensure applications using BigDecimal job arguments are not subject to
|
140
|
+
race conditions during deployment (where a replica running a version of
|
141
|
+
Rails without BigDecimalSerializer fails to deserialize an argument
|
142
|
+
serialized with it), `ActiveJob.use_big_decimal_serializer` is disabled by
|
143
|
+
default, and can be set to true in a following deployment..
|
80
144
|
|
81
|
-
*
|
145
|
+
*Sam Bostock*
|
82
146
|
|
83
|
-
|
84
|
-
|
147
|
+
* Preserve full-precision `enqueued_at` timestamps for serialized jobs,
|
148
|
+
allowing more accurate reporting of how long a job spent waiting in the
|
149
|
+
queue before it was performed.
|
85
150
|
|
86
|
-
|
151
|
+
Retains IS08601 format compatibility.
|
87
152
|
|
88
|
-
|
153
|
+
*Jeremy Daer*
|
89
154
|
|
90
|
-
*
|
155
|
+
* Add `--parent` option to job generator to specify parent class of job.
|
91
156
|
|
157
|
+
Example:
|
92
158
|
|
93
|
-
|
159
|
+
`bin/rails g job process_payment --parent=payment_job` generates:
|
94
160
|
|
95
|
-
|
161
|
+
```ruby
|
162
|
+
class ProcessPaymentJob < PaymentJob
|
163
|
+
# ...
|
164
|
+
end
|
165
|
+
```
|
96
166
|
|
167
|
+
*Gannon McGibbon*
|
97
168
|
|
98
|
-
|
169
|
+
* Add more detailed description to job generator.
|
99
170
|
|
100
|
-
*
|
171
|
+
*Gannon McGibbon*
|
101
172
|
|
173
|
+
* `perform.active_job` notification payloads now include `:db_runtime`, which
|
174
|
+
is the total time (in ms) taken by database queries while performing a job.
|
175
|
+
This value can be used to better understand how a job's time is spent.
|
102
176
|
|
103
|
-
|
177
|
+
*Jonathan Hefner*
|
104
178
|
|
105
|
-
*
|
179
|
+
* Update `ActiveJob::QueueAdapters::QueAdapter` to remove deprecation warning.
|
106
180
|
|
181
|
+
Remove a deprecation warning introduced in que 1.2 to prepare for changes in
|
182
|
+
que 2.0 necessary for Ruby 3 compatibility.
|
107
183
|
|
108
|
-
|
184
|
+
*Damir Zekic* and *Adis Hasovic*
|
109
185
|
|
110
|
-
*
|
186
|
+
* Add missing `bigdecimal` require in `ActiveJob::Arguments`
|
111
187
|
|
188
|
+
Could cause `uninitialized constant ActiveJob::Arguments::BigDecimal (NameError)`
|
189
|
+
when loading Active Job in isolation.
|
112
190
|
|
113
|
-
|
191
|
+
*Jean Boussier*
|
114
192
|
|
115
193
|
* Allow testing `discard_on/retry_on ActiveJob::DeserializationError`
|
116
194
|
|
@@ -118,7 +196,7 @@
|
|
118
196
|
was called before calling `perform_now`. When a record no longer exists
|
119
197
|
and is serialized using GlobalID this led to raising
|
120
198
|
an `ActiveJob::DeserializationError` before reaching `perform_now` call.
|
121
|
-
This
|
199
|
+
This behavior makes difficult testing the job `discard_on/retry_on` logic.
|
122
200
|
|
123
201
|
Now `deserialize_arguments_if_needed` call is postponed to when `perform_now`
|
124
202
|
is called.
|
@@ -143,104 +221,4 @@
|
|
143
221
|
|
144
222
|
*Jacopo Beschi*
|
145
223
|
|
146
|
-
|
147
|
-
## Rails 7.0.0 (December 15, 2021) ##
|
148
|
-
|
149
|
-
* No changes.
|
150
|
-
|
151
|
-
|
152
|
-
## Rails 7.0.0.rc3 (December 14, 2021) ##
|
153
|
-
|
154
|
-
* No changes.
|
155
|
-
|
156
|
-
|
157
|
-
## Rails 7.0.0.rc2 (December 14, 2021) ##
|
158
|
-
|
159
|
-
* No changes.
|
160
|
-
|
161
|
-
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
162
|
-
|
163
|
-
* Remove deprecated `:return_false_on_aborted_enqueue` option.
|
164
|
-
|
165
|
-
*Rafael Mendonça França*
|
166
|
-
|
167
|
-
* Deprecated `Rails.config.active_job.skip_after_callbacks_if_terminated`.
|
168
|
-
|
169
|
-
*Rafael Mendonça França*
|
170
|
-
|
171
|
-
* Removed deprecated behavior that was not halting `after_enqueue`/`after_perform` callbacks when a
|
172
|
-
previous callback was halted with `throw :abort`.
|
173
|
-
|
174
|
-
*Rafael Mendonça França*
|
175
|
-
|
176
|
-
* Raise an `SerializationError` in `Serializer::ModuleSerializer`
|
177
|
-
if the module name is not present.
|
178
|
-
|
179
|
-
*Veerpal Brar*
|
180
|
-
|
181
|
-
|
182
|
-
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
183
|
-
|
184
|
-
* No changes.
|
185
|
-
|
186
|
-
|
187
|
-
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
188
|
-
|
189
|
-
* Allow a job to retry indefinitely
|
190
|
-
|
191
|
-
The `attempts` parameter of the `retry_on` method now accepts the
|
192
|
-
symbol reference `:unlimited` in addition to a specific number of retry
|
193
|
-
attempts to allow a developer to specify that a job should retry
|
194
|
-
forever until it succeeds.
|
195
|
-
|
196
|
-
class MyJob < ActiveJob::Base
|
197
|
-
retry_on(AlwaysRetryException, attempts: :unlimited)
|
198
|
-
|
199
|
-
# the actual job code
|
200
|
-
end
|
201
|
-
|
202
|
-
*Daniel Morton*
|
203
|
-
|
204
|
-
* Added possibility to check on `:priority` in test helper methods
|
205
|
-
`assert_enqueued_with` and `assert_performed_with`.
|
206
|
-
|
207
|
-
*Wojciech Wnętrzak*
|
208
|
-
|
209
|
-
* OpenSSL constants are now used for Digest computations.
|
210
|
-
|
211
|
-
*Dirkjan Bussink*
|
212
|
-
|
213
|
-
* Add a Serializer for the Range class.
|
214
|
-
|
215
|
-
This should allow things like `MyJob.perform_later(range: 1..100)`.
|
216
|
-
|
217
|
-
* Communicate enqueue failures to callers of `perform_later`.
|
218
|
-
|
219
|
-
`perform_later` can now optionally take a block which will execute after
|
220
|
-
the adapter attempts to enqueue the job. The block will receive the job
|
221
|
-
instance as an argument even if the enqueue was not successful.
|
222
|
-
Additionally, `ActiveJob` adapters now have the ability to raise an
|
223
|
-
`ActiveJob::EnqueueError` which will be caught and stored in the job
|
224
|
-
instance so code attempting to enqueue jobs can inspect any raised
|
225
|
-
`EnqueueError` using the block.
|
226
|
-
|
227
|
-
MyJob.perform_later do |job|
|
228
|
-
unless job.successfully_enqueued?
|
229
|
-
if job.enqueue_error&.message == "Redis was unavailable"
|
230
|
-
# invoke some code that will retry the job after a delay
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
*Daniel Morton*
|
236
|
-
|
237
|
-
* Don't log rescuable exceptions defined with `rescue_from`.
|
238
|
-
|
239
|
-
*Hu Hailin*
|
240
|
-
|
241
|
-
* Allow `rescue_from` to rescue all exceptions.
|
242
|
-
|
243
|
-
*Adrianna Chang*, *Étienne Barrié*
|
244
|
-
|
245
|
-
|
246
|
-
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activejob/CHANGELOG.md) for previous changes.
|
224
|
+
Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/activejob/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -10,14 +10,14 @@ that makes it easy to turn any mailing into a job for running later. That's
|
|
10
10
|
one of the most common jobs in a modern web application: sending emails outside
|
11
11
|
the request-response cycle, so the user doesn't have to wait on it.
|
12
12
|
|
13
|
-
The main point is to ensure that all Rails apps will have a job infrastructure
|
13
|
+
The main point is to ensure that all \Rails apps will have a job infrastructure
|
14
14
|
in place, even if it's in the form of an "immediate runner". We can then have
|
15
15
|
framework features and other gems build on top of that, without having to worry
|
16
16
|
about API differences between Delayed Job and Resque. Picking your queuing
|
17
17
|
backend becomes more of an operational concern, then. And you'll be able to
|
18
18
|
switch between them without having to rewrite your jobs.
|
19
19
|
|
20
|
-
You can read more about Active Job in the [Active Job Basics](https://
|
20
|
+
You can read more about Active Job in the [Active Job Basics](https://guides.rubyonrails.org/active_job_basics.html) guide.
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
data/lib/active_job/arguments.rb
CHANGED
@@ -47,7 +47,7 @@ module ActiveJob
|
|
47
47
|
|
48
48
|
private
|
49
49
|
# :nodoc:
|
50
|
-
PERMITTED_TYPES = [ NilClass, String, Integer, Float,
|
50
|
+
PERMITTED_TYPES = [ NilClass, String, Integer, Float, TrueClass, FalseClass ]
|
51
51
|
# :nodoc:
|
52
52
|
GLOBALID_KEY = "_aj_globalid"
|
53
53
|
# :nodoc:
|
@@ -70,28 +70,6 @@ module ActiveJob
|
|
70
70
|
private_constant :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY,
|
71
71
|
:SYMBOL_KEYS_KEY, :RUBY2_KEYWORDS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
|
72
72
|
|
73
|
-
unless Hash.respond_to?(:ruby2_keywords_hash?) && Hash.respond_to?(:ruby2_keywords_hash)
|
74
|
-
using Module.new {
|
75
|
-
refine Hash do
|
76
|
-
class << Hash
|
77
|
-
def ruby2_keywords_hash?(hash)
|
78
|
-
!new(*[hash]).default.equal?(hash)
|
79
|
-
end
|
80
|
-
|
81
|
-
def ruby2_keywords_hash(hash)
|
82
|
-
_ruby2_keywords_hash(**hash)
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
def _ruby2_keywords_hash(*args)
|
87
|
-
args.last
|
88
|
-
end
|
89
|
-
ruby2_keywords(:_ruby2_keywords_hash)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
73
|
def serialize_argument(argument)
|
96
74
|
case argument
|
97
75
|
when *PERMITTED_TYPES
|
@@ -115,16 +93,27 @@ module ActiveJob
|
|
115
93
|
when -> (arg) { arg.respond_to?(:permitted?) && arg.respond_to?(:to_h) }
|
116
94
|
serialize_indifferent_hash(argument.to_h)
|
117
95
|
else
|
96
|
+
if BigDecimal === argument && !ActiveJob.use_big_decimal_serializer
|
97
|
+
ActiveJob.deprecator.warn(<<~MSG)
|
98
|
+
Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
|
99
|
+
Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
|
100
|
+
|
101
|
+
Note that if you application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
|
102
|
+
This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
|
103
|
+
MSG
|
104
|
+
return argument
|
105
|
+
end
|
106
|
+
|
118
107
|
Serializers.serialize(argument)
|
119
108
|
end
|
120
109
|
end
|
121
110
|
|
122
111
|
def deserialize_argument(argument)
|
123
112
|
case argument
|
124
|
-
when String
|
125
|
-
argument
|
126
113
|
when *PERMITTED_TYPES
|
127
114
|
argument
|
115
|
+
when BigDecimal # BigDecimal may have been legacy serialized; Remove in 7.2
|
116
|
+
argument
|
128
117
|
when Array
|
129
118
|
argument.map { |arg| deserialize_argument(arg) }
|
130
119
|
when Hash
|
data/lib/active_job/base.rb
CHANGED
@@ -15,7 +15,7 @@ require "active_job/timezones"
|
|
15
15
|
require "active_job/translation"
|
16
16
|
|
17
17
|
module ActiveJob # :nodoc:
|
18
|
-
# = Active Job
|
18
|
+
# = Active Job \Base
|
19
19
|
#
|
20
20
|
# Active Job objects can be configured to work with different backend
|
21
21
|
# queuing frameworks. To specify a queue adapter to use:
|
data/lib/active_job/callbacks.rb
CHANGED
@@ -4,7 +4,7 @@ require "active_support/callbacks"
|
|
4
4
|
require "active_support/core_ext/module/attribute_accessors"
|
5
5
|
|
6
6
|
module ActiveJob
|
7
|
-
# = Active Job Callbacks
|
7
|
+
# = Active Job \Callbacks
|
8
8
|
#
|
9
9
|
# Active Job provides hooks during the life cycle of a job. Callbacks allow you
|
10
10
|
# to trigger logic during this cycle. Available callbacks are:
|
@@ -28,9 +28,6 @@ module ActiveJob
|
|
28
28
|
end
|
29
29
|
|
30
30
|
included do
|
31
|
-
cattr_accessor :skip_after_callbacks_if_terminated, instance_accessor: false, default: false
|
32
|
-
singleton_class.deprecate :skip_after_callbacks_if_terminated, :skip_after_callbacks_if_terminated=
|
33
|
-
|
34
31
|
define_callbacks :perform, skip_after_callbacks_if_terminated: true
|
35
32
|
define_callbacks :enqueue, skip_after_callbacks_if_terminated: true
|
36
33
|
end
|
data/lib/active_job/core.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveJob
|
4
|
+
# = Active Job \Core
|
5
|
+
#
|
4
6
|
# Provides general behavior that will be included into every Active Job
|
5
7
|
# object that inherits from ActiveJob::Base.
|
6
8
|
module Core
|
@@ -10,8 +12,10 @@ module ActiveJob
|
|
10
12
|
attr_accessor :arguments
|
11
13
|
attr_writer :serialized_arguments
|
12
14
|
|
13
|
-
#
|
14
|
-
|
15
|
+
# Time when the job should be performed
|
16
|
+
attr_reader :scheduled_at
|
17
|
+
|
18
|
+
attr_reader :_scheduled_at_time # :nodoc:
|
15
19
|
|
16
20
|
# Job Identifier
|
17
21
|
attr_accessor :job_id
|
@@ -92,6 +96,8 @@ module ActiveJob
|
|
92
96
|
@arguments = arguments
|
93
97
|
@job_id = SecureRandom.uuid
|
94
98
|
@queue_name = self.class.queue_name
|
99
|
+
@scheduled_at = nil
|
100
|
+
@_scheduled_at_time = nil
|
95
101
|
@priority = self.class.priority
|
96
102
|
@executions = 0
|
97
103
|
@exception_executions = {}
|
@@ -113,7 +119,8 @@ module ActiveJob
|
|
113
119
|
"exception_executions" => exception_executions,
|
114
120
|
"locale" => I18n.locale.to_s,
|
115
121
|
"timezone" => timezone,
|
116
|
-
"enqueued_at" => Time.now.utc.iso8601
|
122
|
+
"enqueued_at" => Time.now.utc.iso8601(9),
|
123
|
+
"scheduled_at" => _scheduled_at_time ? _scheduled_at_time.utc.iso8601(9) : nil,
|
117
124
|
}
|
118
125
|
end
|
119
126
|
|
@@ -153,19 +160,32 @@ module ActiveJob
|
|
153
160
|
self.exception_executions = job_data["exception_executions"]
|
154
161
|
self.locale = job_data["locale"] || I18n.locale.to_s
|
155
162
|
self.timezone = job_data["timezone"] || Time.zone&.name
|
156
|
-
self.enqueued_at = job_data["enqueued_at"]
|
163
|
+
self.enqueued_at = Time.iso8601(job_data["enqueued_at"]) if job_data["enqueued_at"]
|
164
|
+
self.scheduled_at = Time.iso8601(job_data["scheduled_at"]) if job_data["scheduled_at"]
|
157
165
|
end
|
158
166
|
|
159
167
|
# Configures the job with the given options.
|
160
168
|
def set(options = {}) # :nodoc:
|
161
|
-
self.scheduled_at = options[:wait].seconds.from_now
|
162
|
-
self.scheduled_at = options[:wait_until]
|
169
|
+
self.scheduled_at = options[:wait].seconds.from_now if options[:wait]
|
170
|
+
self.scheduled_at = options[:wait_until] if options[:wait_until]
|
163
171
|
self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
|
164
172
|
self.priority = options[:priority].to_i if options[:priority]
|
165
173
|
|
166
174
|
self
|
167
175
|
end
|
168
176
|
|
177
|
+
def scheduled_at=(value)
|
178
|
+
@_scheduled_at_time = if value&.is_a?(Numeric)
|
179
|
+
ActiveJob.deprecator.warn(<<~MSG.squish)
|
180
|
+
Assigning a numeric/epoch value to scheduled_at is deprecated. Use a Time object instead.
|
181
|
+
MSG
|
182
|
+
Time.at(value)
|
183
|
+
else
|
184
|
+
value
|
185
|
+
end
|
186
|
+
@scheduled_at = value
|
187
|
+
end
|
188
|
+
|
169
189
|
private
|
170
190
|
def serialize_arguments_if_needed(arguments)
|
171
191
|
if arguments_serialized?
|
data/lib/active_job/enqueuing.rb
CHANGED
@@ -9,6 +9,36 @@ module ActiveJob
|
|
9
9
|
# why the adapter was unexpectedly unable to enqueue a job.
|
10
10
|
class EnqueueError < StandardError; end
|
11
11
|
|
12
|
+
class << self
|
13
|
+
# Push many jobs onto the queue at once without running enqueue callbacks.
|
14
|
+
# Queue adapters may communicate the enqueue status of each job by setting
|
15
|
+
# successfully_enqueued and/or enqueue_error on the passed-in job instances.
|
16
|
+
def perform_all_later(*jobs)
|
17
|
+
jobs.flatten!
|
18
|
+
jobs.group_by(&:queue_adapter).each do |queue_adapter, adapter_jobs|
|
19
|
+
instrument_enqueue_all(queue_adapter, adapter_jobs) do
|
20
|
+
if queue_adapter.respond_to?(:enqueue_all)
|
21
|
+
queue_adapter.enqueue_all(adapter_jobs)
|
22
|
+
else
|
23
|
+
adapter_jobs.each do |job|
|
24
|
+
job.successfully_enqueued = false
|
25
|
+
if job.scheduled_at
|
26
|
+
queue_adapter.enqueue_at(job, job._scheduled_at_time.to_f)
|
27
|
+
else
|
28
|
+
queue_adapter.enqueue(job)
|
29
|
+
end
|
30
|
+
job.successfully_enqueued = true
|
31
|
+
rescue EnqueueError => e
|
32
|
+
job.enqueue_error = e
|
33
|
+
end
|
34
|
+
adapter_jobs.count(&:successfully_enqueued?)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
12
42
|
module Enqueuing
|
13
43
|
extend ActiveSupport::Concern
|
14
44
|
|
@@ -62,7 +92,7 @@ module ActiveJob
|
|
62
92
|
|
63
93
|
run_callbacks :enqueue do
|
64
94
|
if scheduled_at
|
65
|
-
queue_adapter.enqueue_at self,
|
95
|
+
queue_adapter.enqueue_at self, _scheduled_at_time.to_f
|
66
96
|
else
|
67
97
|
queue_adapter.enqueue self
|
68
98
|
end
|