activejob 7.0.8.7 → 7.2.2.1
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 +40 -229
- data/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/lib/active_job/arguments.rb +18 -32
- data/lib/active_job/base.rb +1 -1
- data/lib/active_job/callbacks.rb +3 -8
- data/lib/active_job/configured_job.rb +4 -0
- data/lib/active_job/core.rb +11 -6
- data/lib/active_job/deprecator.rb +7 -0
- data/lib/active_job/enqueue_after_transaction_commit.rb +28 -0
- data/lib/active_job/enqueuing.rb +71 -12
- data/lib/active_job/exceptions.rb +44 -7
- data/lib/active_job/execution.rb +5 -2
- data/lib/active_job/gem_version.rb +4 -4
- data/lib/active_job/instrumentation.rb +18 -10
- data/lib/active_job/log_subscriber.rb +80 -8
- data/lib/active_job/logging.rb +16 -2
- data/lib/active_job/queue_adapter.rb +18 -6
- data/lib/active_job/queue_adapters/abstract_adapter.rb +27 -0
- data/lib/active_job/queue_adapters/async_adapter.rb +3 -3
- data/lib/active_job/queue_adapters/backburner_adapter.rb +8 -4
- data/lib/active_job/queue_adapters/delayed_job_adapter.rb +10 -2
- data/lib/active_job/queue_adapters/inline_adapter.rb +6 -2
- data/lib/active_job/queue_adapters/queue_classic_adapter.rb +13 -5
- data/lib/active_job/queue_adapters/resque_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +43 -15
- data/lib/active_job/queue_adapters/sneakers_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +4 -4
- data/lib/active_job/queue_adapters/test_adapter.rb +13 -5
- data/lib/active_job/queue_adapters.rb +9 -7
- data/lib/active_job/queue_priority.rb +18 -1
- data/lib/active_job/railtie.rb +38 -7
- 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/object_serializer.rb +2 -0
- data/lib/active_job/serializers/time_with_zone_serializer.rb +11 -2
- data/lib/active_job/serializers.rb +7 -3
- data/lib/active_job/test_helper.rb +60 -19
- data/lib/active_job/version.rb +1 -1
- data/lib/active_job.rb +34 -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 -8
- 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: c3b47492def92c2f9d51610a3b8ca696cbb32ff69fe45107ebaf478a69abc65f
|
4
|
+
data.tar.gz: f05813374e5dec3e6b9e138585ef9ef23c87640187a42ea03e7db9d50d1e2362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58e96af8f140d46c83bc3d9231ee6e8c330d71e724def12d20844d5af4280b12a4de63ba3c7e58157d32295193c55405fb292071c6f0494416f66ea46ad658a6
|
7
|
+
data.tar.gz: a5f662c33aa37b48aa7643299cddaf5f76559feb7820468862b71aae7c0f725cf25ad098b0df2d951c810d76abaa10e49e24bdac3589b4c6bd9b683335856424
|
data/CHANGELOG.md
CHANGED
@@ -1,281 +1,92 @@
|
|
1
|
-
## Rails 7.
|
1
|
+
## Rails 7.2.2.1 (December 10, 2024) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails 7.
|
6
|
+
## Rails 7.2.2 (October 30, 2024) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails 7.
|
11
|
+
## Rails 7.2.1.2 (October 23, 2024) ##
|
12
12
|
|
13
13
|
* No changes.
|
14
14
|
|
15
15
|
|
16
|
-
## Rails 7.
|
16
|
+
## Rails 7.2.1.1 (October 15, 2024) ##
|
17
17
|
|
18
18
|
* No changes.
|
19
19
|
|
20
20
|
|
21
|
-
## Rails 7.
|
21
|
+
## Rails 7.2.1 (August 22, 2024) ##
|
22
22
|
|
23
23
|
* No changes.
|
24
24
|
|
25
25
|
|
26
|
-
## Rails 7.0
|
27
|
-
|
28
|
-
* No changes.
|
29
|
-
|
30
|
-
|
31
|
-
## Rails 7.0.8.1 (February 21, 2024) ##
|
32
|
-
|
33
|
-
* No changes.
|
34
|
-
|
35
|
-
|
36
|
-
## Rails 7.0.8 (September 09, 2023) ##
|
37
|
-
|
38
|
-
* Fix Active Job log message to correctly report a job failed to enqueue
|
39
|
-
when the adapter raises an `ActiveJob::EnqueueError`.
|
40
|
-
|
41
|
-
*Ben Sheldon*
|
42
|
-
|
43
|
-
|
44
|
-
## Rails 7.0.7.2 (August 22, 2023) ##
|
45
|
-
|
46
|
-
* No changes.
|
47
|
-
|
48
|
-
|
49
|
-
## Rails 7.0.7.1 (August 22, 2023) ##
|
50
|
-
|
51
|
-
* No changes.
|
52
|
-
|
53
|
-
|
54
|
-
## Rails 7.0.7 (August 09, 2023) ##
|
55
|
-
|
56
|
-
* No changes.
|
57
|
-
|
58
|
-
|
59
|
-
## Rails 7.0.6 (June 29, 2023) ##
|
60
|
-
|
61
|
-
* Fix error Active Job passed class with `permitted?`.
|
62
|
-
|
63
|
-
*Alex Baldwin*
|
64
|
-
|
65
|
-
|
66
|
-
## Rails 7.0.5.1 (June 26, 2023) ##
|
67
|
-
|
68
|
-
* No changes.
|
26
|
+
## Rails 7.2.0 (August 09, 2024) ##
|
69
27
|
|
28
|
+
* All tests now respect the `active_job.queue_adapter` config.
|
70
29
|
|
71
|
-
|
30
|
+
Previously if you had set `config.active_job.queue_adapter` in your `config/application.rb`
|
31
|
+
or `config/environments/test.rb` file, the adapter you selected was previously not used consistently
|
32
|
+
across all tests. In some tests your adapter would be used, but other tests would use the `TestAdapter`.
|
72
33
|
|
73
|
-
|
34
|
+
In Rails 7.2, all tests will respect the `queue_adapter` config if provided. If no config is provided,
|
35
|
+
the `TestAdapter` will continue to be used.
|
74
36
|
|
75
|
-
|
76
|
-
|
77
|
-
* Don't double log the `job` when using `ActiveRecord::QueryLog`
|
78
|
-
|
79
|
-
Previously if you set `config.active_record.query_log_tags` to an array that included
|
80
|
-
`:job`, the job name would get logged twice. This bug has been fixed.
|
37
|
+
See [#48585](https://github.com/rails/rails/pull/48585) for more details.
|
81
38
|
|
82
39
|
*Alex Ghiculescu*
|
83
40
|
|
41
|
+
* Make Active Job transaction aware when used conjointly with Active Record.
|
84
42
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
## Rails 7.0.4.2 (January 24, 2023) ##
|
91
|
-
|
92
|
-
* No changes.
|
93
|
-
|
94
|
-
|
95
|
-
## Rails 7.0.4.1 (January 17, 2023) ##
|
96
|
-
|
97
|
-
* No changes.
|
98
|
-
|
99
|
-
|
100
|
-
## Rails 7.0.4 (September 09, 2022) ##
|
101
|
-
|
102
|
-
* Update `ActiveJob::QueueAdapters::QueAdapter` to remove deprecation warning.
|
103
|
-
|
104
|
-
Remove a deprecation warning introduced in que 1.2 to prepare for changes in
|
105
|
-
que 2.0 necessary for Ruby 3 compatibility.
|
106
|
-
|
107
|
-
*Damir Zekic* and *Adis Hasovic*
|
108
|
-
|
109
|
-
## Rails 7.0.3.1 (July 12, 2022) ##
|
110
|
-
|
111
|
-
* No changes.
|
112
|
-
|
113
|
-
|
114
|
-
## Rails 7.0.3 (May 09, 2022) ##
|
115
|
-
|
116
|
-
* Add missing `bigdecimal` require in `ActiveJob::Arguments`
|
117
|
-
|
118
|
-
Could cause `uninitialized constant ActiveJob::Arguments::BigDecimal (NameError)`
|
119
|
-
when loading Active Job in isolation.
|
120
|
-
|
121
|
-
*Jean Boussier*
|
122
|
-
|
123
|
-
## Rails 7.0.2.4 (April 26, 2022) ##
|
124
|
-
|
125
|
-
* No changes.
|
126
|
-
|
127
|
-
|
128
|
-
## Rails 7.0.2.3 (March 08, 2022) ##
|
129
|
-
|
130
|
-
* No changes.
|
131
|
-
|
132
|
-
|
133
|
-
## Rails 7.0.2.2 (February 11, 2022) ##
|
134
|
-
|
135
|
-
* No changes.
|
136
|
-
|
137
|
-
|
138
|
-
## Rails 7.0.2.1 (February 11, 2022) ##
|
139
|
-
|
140
|
-
* No changes.
|
141
|
-
|
142
|
-
|
143
|
-
## Rails 7.0.2 (February 08, 2022) ##
|
144
|
-
|
145
|
-
* No changes.
|
146
|
-
|
147
|
-
|
148
|
-
## Rails 7.0.1 (January 06, 2022) ##
|
149
|
-
|
150
|
-
* Allow testing `discard_on/retry_on ActiveJob::DeserializationError`
|
151
|
-
|
152
|
-
Previously in `perform_enqueued_jobs`, `deserialize_arguments_if_needed`
|
153
|
-
was called before calling `perform_now`. When a record no longer exists
|
154
|
-
and is serialized using GlobalID this led to raising
|
155
|
-
an `ActiveJob::DeserializationError` before reaching `perform_now` call.
|
156
|
-
This behaviour makes difficult testing the job `discard_on/retry_on` logic.
|
157
|
-
|
158
|
-
Now `deserialize_arguments_if_needed` call is postponed to when `perform_now`
|
159
|
-
is called.
|
160
|
-
|
161
|
-
Example:
|
43
|
+
A common mistake with Active Job is to enqueue jobs from inside a transaction,
|
44
|
+
causing them to potentially be picked and ran by another process, before the
|
45
|
+
transaction is committed, which may result in various errors.
|
162
46
|
|
163
47
|
```ruby
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
def perform(user)
|
168
|
-
# ...
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# In the test
|
173
|
-
User.destroy_all
|
174
|
-
assert_nothing_raised do
|
175
|
-
perform_enqueued_jobs only: UpdateUserJob
|
48
|
+
Topic.transaction do
|
49
|
+
topic = Topic.create(...)
|
50
|
+
NewTopicNotificationJob.perform_later(topic)
|
176
51
|
end
|
177
52
|
```
|
178
53
|
|
179
|
-
|
54
|
+
Now Active Job will automatically defer the enqueuing to after the transaction is committed,
|
55
|
+
and drop the job if the transaction is rolled back.
|
180
56
|
|
57
|
+
Various queue implementations can choose to disable this behavior, and users can disable it,
|
58
|
+
or force it on a per job basis:
|
181
59
|
|
182
|
-
|
183
|
-
|
184
|
-
|
60
|
+
```ruby
|
61
|
+
class NewTopicNotificationJob < ApplicationJob
|
62
|
+
self.enqueue_after_transaction_commit = :never # or `:always` or `:default`
|
63
|
+
end
|
64
|
+
```
|
185
65
|
|
66
|
+
*Jean Boussier*, *Cristian Bica*
|
186
67
|
|
187
|
-
|
68
|
+
* Do not trigger immediate loading of `ActiveJob::Base` when loading `ActiveJob::TestHelper`.
|
188
69
|
|
189
|
-
*
|
70
|
+
*Maxime Réty*
|
190
71
|
|
72
|
+
* Preserve the serialized timezone when deserializing `ActiveSupport::TimeWithZone` arguments.
|
191
73
|
|
192
|
-
|
74
|
+
*Joshua Young*
|
193
75
|
|
194
|
-
*
|
195
|
-
|
196
|
-
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
197
|
-
|
198
|
-
* Remove deprecated `:return_false_on_aborted_enqueue` option.
|
76
|
+
* Remove deprecated `:exponentially_longer` value for the `:wait` in `retry_on`.
|
199
77
|
|
200
78
|
*Rafael Mendonça França*
|
201
79
|
|
202
|
-
*
|
80
|
+
* Remove deprecated support to set numeric values to `scheduled_at` attribute.
|
203
81
|
|
204
82
|
*Rafael Mendonça França*
|
205
83
|
|
206
|
-
*
|
207
|
-
previous callback was halted with `throw :abort`.
|
84
|
+
* Deprecate `Rails.application.config.active_job.use_big_decimal_serialize`.
|
208
85
|
|
209
86
|
*Rafael Mendonça França*
|
210
87
|
|
211
|
-
*
|
212
|
-
if the module name is not present.
|
213
|
-
|
214
|
-
*Veerpal Brar*
|
215
|
-
|
216
|
-
|
217
|
-
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
218
|
-
|
219
|
-
* No changes.
|
220
|
-
|
221
|
-
|
222
|
-
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
223
|
-
|
224
|
-
* Allow a job to retry indefinitely
|
225
|
-
|
226
|
-
The `attempts` parameter of the `retry_on` method now accepts the
|
227
|
-
symbol reference `:unlimited` in addition to a specific number of retry
|
228
|
-
attempts to allow a developer to specify that a job should retry
|
229
|
-
forever until it succeeds.
|
230
|
-
|
231
|
-
class MyJob < ActiveJob::Base
|
232
|
-
retry_on(AlwaysRetryException, attempts: :unlimited)
|
233
|
-
|
234
|
-
# the actual job code
|
235
|
-
end
|
236
|
-
|
237
|
-
*Daniel Morton*
|
238
|
-
|
239
|
-
* Added possibility to check on `:priority` in test helper methods
|
240
|
-
`assert_enqueued_with` and `assert_performed_with`.
|
241
|
-
|
242
|
-
*Wojciech Wnętrzak*
|
243
|
-
|
244
|
-
* OpenSSL constants are now used for Digest computations.
|
245
|
-
|
246
|
-
*Dirkjan Bussink*
|
247
|
-
|
248
|
-
* Add a Serializer for the Range class.
|
249
|
-
|
250
|
-
This should allow things like `MyJob.perform_later(range: 1..100)`.
|
251
|
-
|
252
|
-
* Communicate enqueue failures to callers of `perform_later`.
|
253
|
-
|
254
|
-
`perform_later` can now optionally take a block which will execute after
|
255
|
-
the adapter attempts to enqueue the job. The block will receive the job
|
256
|
-
instance as an argument even if the enqueue was not successful.
|
257
|
-
Additionally, `ActiveJob` adapters now have the ability to raise an
|
258
|
-
`ActiveJob::EnqueueError` which will be caught and stored in the job
|
259
|
-
instance so code attempting to enqueue jobs can inspect any raised
|
260
|
-
`EnqueueError` using the block.
|
261
|
-
|
262
|
-
MyJob.perform_later do |job|
|
263
|
-
unless job.successfully_enqueued?
|
264
|
-
if job.enqueue_error&.message == "Redis was unavailable"
|
265
|
-
# invoke some code that will retry the job after a delay
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
*Daniel Morton*
|
271
|
-
|
272
|
-
* Don't log rescuable exceptions defined with `rescue_from`.
|
273
|
-
|
274
|
-
*Hu Hailin*
|
275
|
-
|
276
|
-
* Allow `rescue_from` to rescue all exceptions.
|
277
|
-
|
278
|
-
*Adrianna Chang*, *Étienne Barrié*
|
88
|
+
* Remove deprecated primitive serializer for `BigDecimal` arguments.
|
279
89
|
|
90
|
+
*Rafael Mendonça França*
|
280
91
|
|
281
|
-
Please check [
|
92
|
+
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-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
@@ -46,8 +46,6 @@ module ActiveJob
|
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
49
|
-
# :nodoc:
|
50
|
-
PERMITTED_TYPES = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
|
51
49
|
# :nodoc:
|
52
50
|
GLOBALID_KEY = "_aj_globalid"
|
53
51
|
# :nodoc:
|
@@ -67,35 +65,23 @@ module ActiveJob
|
|
67
65
|
OBJECT_SERIALIZER_KEY, OBJECT_SERIALIZER_KEY.to_sym,
|
68
66
|
WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
|
69
67
|
]
|
70
|
-
private_constant :
|
68
|
+
private_constant :RESERVED_KEYS, :GLOBALID_KEY,
|
71
69
|
:SYMBOL_KEYS_KEY, :RUBY2_KEYWORDS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
|
72
70
|
|
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
71
|
def serialize_argument(argument)
|
96
72
|
case argument
|
97
|
-
when
|
73
|
+
when nil, true, false, Integer, Float # Types that can hardly be subclassed
|
98
74
|
argument
|
75
|
+
when String
|
76
|
+
if argument.class == String
|
77
|
+
argument
|
78
|
+
else
|
79
|
+
begin
|
80
|
+
Serializers.serialize(argument)
|
81
|
+
rescue SerializationError
|
82
|
+
argument
|
83
|
+
end
|
84
|
+
end
|
99
85
|
when GlobalID::Identification
|
100
86
|
convert_to_global_id_hash(argument)
|
101
87
|
when Array
|
@@ -112,18 +98,18 @@ module ActiveJob
|
|
112
98
|
result = serialize_hash(argument)
|
113
99
|
result[aj_hash_key] = symbol_keys
|
114
100
|
result
|
115
|
-
when -> (arg) { arg.respond_to?(:permitted?) && arg.respond_to?(:to_h) }
|
116
|
-
serialize_indifferent_hash(argument.to_h)
|
117
101
|
else
|
118
|
-
|
102
|
+
if argument.respond_to?(:permitted?) && argument.respond_to?(:to_h)
|
103
|
+
serialize_indifferent_hash(argument.to_h)
|
104
|
+
else
|
105
|
+
Serializers.serialize(argument)
|
106
|
+
end
|
119
107
|
end
|
120
108
|
end
|
121
109
|
|
122
110
|
def deserialize_argument(argument)
|
123
111
|
case argument
|
124
|
-
when String
|
125
|
-
argument
|
126
|
-
when *PERMITTED_TYPES
|
112
|
+
when nil, true, false, String, Integer, Float
|
127
113
|
argument
|
128
114
|
when Array
|
129
115
|
argument.map { |arg| deserialize_argument(arg) }
|
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:
|
@@ -15,9 +15,6 @@ module ActiveJob
|
|
15
15
|
# * <tt>before_perform</tt>
|
16
16
|
# * <tt>around_perform</tt>
|
17
17
|
# * <tt>after_perform</tt>
|
18
|
-
#
|
19
|
-
# NOTE: Calling the same callback multiple times will overwrite previous callback definitions.
|
20
|
-
#
|
21
18
|
module Callbacks
|
22
19
|
extend ActiveSupport::Concern
|
23
20
|
include ActiveSupport::Callbacks
|
@@ -28,9 +25,6 @@ module ActiveJob
|
|
28
25
|
end
|
29
26
|
|
30
27
|
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
28
|
define_callbacks :perform, skip_after_callbacks_if_terminated: true
|
35
29
|
define_callbacks :enqueue, skip_after_callbacks_if_terminated: true
|
36
30
|
end
|
@@ -135,7 +129,8 @@ module ActiveJob
|
|
135
129
|
# queue_as :default
|
136
130
|
#
|
137
131
|
# after_enqueue do |job|
|
138
|
-
#
|
132
|
+
# result = job.successfully_enqueued? ? "success" : "failure"
|
133
|
+
# $statsd.increment "enqueue-video-job.#{result}"
|
139
134
|
# end
|
140
135
|
#
|
141
136
|
# def perform(video_id)
|
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,7 +12,7 @@ module ActiveJob
|
|
10
12
|
attr_accessor :arguments
|
11
13
|
attr_writer :serialized_arguments
|
12
14
|
|
13
|
-
#
|
15
|
+
# Time when the job should be performed
|
14
16
|
attr_accessor :scheduled_at
|
15
17
|
|
16
18
|
# Job Identifier
|
@@ -92,6 +94,7 @@ module ActiveJob
|
|
92
94
|
@arguments = arguments
|
93
95
|
@job_id = SecureRandom.uuid
|
94
96
|
@queue_name = self.class.queue_name
|
97
|
+
@scheduled_at = nil
|
95
98
|
@priority = self.class.priority
|
96
99
|
@executions = 0
|
97
100
|
@exception_executions = {}
|
@@ -113,7 +116,8 @@ module ActiveJob
|
|
113
116
|
"exception_executions" => exception_executions,
|
114
117
|
"locale" => I18n.locale.to_s,
|
115
118
|
"timezone" => timezone,
|
116
|
-
"enqueued_at" => Time.now.utc.iso8601
|
119
|
+
"enqueued_at" => Time.now.utc.iso8601(9),
|
120
|
+
"scheduled_at" => scheduled_at ? scheduled_at.utc.iso8601(9) : nil,
|
117
121
|
}
|
118
122
|
end
|
119
123
|
|
@@ -153,13 +157,14 @@ module ActiveJob
|
|
153
157
|
self.exception_executions = job_data["exception_executions"]
|
154
158
|
self.locale = job_data["locale"] || I18n.locale.to_s
|
155
159
|
self.timezone = job_data["timezone"] || Time.zone&.name
|
156
|
-
self.enqueued_at = job_data["enqueued_at"]
|
160
|
+
self.enqueued_at = Time.iso8601(job_data["enqueued_at"]) if job_data["enqueued_at"]
|
161
|
+
self.scheduled_at = Time.iso8601(job_data["scheduled_at"]) if job_data["scheduled_at"]
|
157
162
|
end
|
158
163
|
|
159
164
|
# Configures the job with the given options.
|
160
165
|
def set(options = {}) # :nodoc:
|
161
|
-
self.scheduled_at = options[:wait].seconds.from_now
|
162
|
-
self.scheduled_at = options[:wait_until]
|
166
|
+
self.scheduled_at = options[:wait].seconds.from_now if options[:wait]
|
167
|
+
self.scheduled_at = options[:wait_until] if options[:wait_until]
|
163
168
|
self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
|
164
169
|
self.priority = options[:priority].to_i if options[:priority]
|
165
170
|
|
@@ -191,7 +196,7 @@ module ActiveJob
|
|
191
196
|
end
|
192
197
|
|
193
198
|
def arguments_serialized?
|
194
|
-
|
199
|
+
@serialized_arguments
|
195
200
|
end
|
196
201
|
end
|
197
202
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module EnqueueAfterTransactionCommit # :nodoc:
|
5
|
+
private
|
6
|
+
def raw_enqueue
|
7
|
+
after_transaction = case self.class.enqueue_after_transaction_commit
|
8
|
+
when :always
|
9
|
+
true
|
10
|
+
when :never
|
11
|
+
false
|
12
|
+
else # :default
|
13
|
+
queue_adapter.enqueue_after_transaction_commit?
|
14
|
+
end
|
15
|
+
|
16
|
+
if after_transaction
|
17
|
+
self.successfully_enqueued = true
|
18
|
+
ActiveRecord.after_all_transactions_commit do
|
19
|
+
self.successfully_enqueued = false
|
20
|
+
super
|
21
|
+
end
|
22
|
+
self
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|