activejob 7.0.8.1 → 7.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +159 -137
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +2 -2
  5. data/lib/active_job/arguments.rb +28 -31
  6. data/lib/active_job/base.rb +1 -1
  7. data/lib/active_job/callbacks.rb +3 -5
  8. data/lib/active_job/configured_job.rb +4 -0
  9. data/lib/active_job/core.rb +26 -6
  10. data/lib/active_job/deprecator.rb +7 -0
  11. data/lib/active_job/enqueuing.rb +31 -1
  12. data/lib/active_job/exceptions.rb +48 -5
  13. data/lib/active_job/execution.rb +5 -1
  14. data/lib/active_job/gem_version.rb +4 -4
  15. data/lib/active_job/instrumentation.rb +18 -10
  16. data/lib/active_job/log_subscriber.rb +80 -8
  17. data/lib/active_job/queue_adapter.rb +13 -2
  18. data/lib/active_job/queue_adapters/async_adapter.rb +2 -2
  19. data/lib/active_job/queue_adapters/backburner_adapter.rb +7 -3
  20. data/lib/active_job/queue_adapters/delayed_job_adapter.rb +1 -1
  21. data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
  22. data/lib/active_job/queue_adapters/queue_classic_adapter.rb +4 -4
  23. data/lib/active_job/queue_adapters/resque_adapter.rb +1 -1
  24. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +42 -14
  25. data/lib/active_job/queue_adapters/sneakers_adapter.rb +1 -1
  26. data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +3 -3
  27. data/lib/active_job/queue_adapters/test_adapter.rb +3 -3
  28. data/lib/active_job/queue_adapters.rb +8 -7
  29. data/lib/active_job/queue_priority.rb +18 -1
  30. data/lib/active_job/railtie.rb +25 -6
  31. data/lib/active_job/serializers/big_decimal_serializer.rb +22 -0
  32. data/lib/active_job/serializers/duration_serializer.rb +4 -2
  33. data/lib/active_job/serializers/time_with_zone_serializer.rb +11 -2
  34. data/lib/active_job/serializers.rb +7 -3
  35. data/lib/active_job/test_helper.rb +32 -14
  36. data/lib/active_job/version.rb +1 -1
  37. data/lib/active_job.rb +26 -4
  38. data/lib/rails/generators/job/USAGE +19 -0
  39. data/lib/rails/generators/job/job_generator.rb +6 -2
  40. data/lib/rails/generators/job/templates/job.rb.tt +1 -1
  41. metadata +10 -8
  42. 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: 17f918517c8501976c3d127a7a9acbee9d022844599ce3b66b2b34746e29b231
4
- data.tar.gz: d24baee9c1bd3dd738a8f6bad97c0f25a1487e6a2d62d81032f7f70356b887ed
3
+ metadata.gz: d507be0c52b0b92769dc3ca1e30a1abb829a16cc1f094aa9182277aedbce6a44
4
+ data.tar.gz: 2cb49b7a6637d18897d16383837ffffb112de3d399c5a700be6f45942ff24ab5
5
5
  SHA512:
6
- metadata.gz: c474d1640b1bc0bdc4612dbcf87e7d36a0c23436e39bff2050cc6adcb43cd385c3342e878f6ee2a1fe193bf0ac782859cd38a65f75daca922ea4d5fbeb22aa94
7
- data.tar.gz: a947dfaf38b92244ead6b1cb442cdb6ee986c58f2f3ba4a54138ab62ac976c80f7c27987025884fdfb85ed5c2b37a69ddf1c56f6364f5bdacc095f8ec770e676
6
+ metadata.gz: eb2ab18a2d1fbc72ac35228b1822ce114cf8e684c11dafd3400888a745f0136569098ffc2725cadaeddf066358e49016fb2b976bf25a986e7ab3aee36835f019
7
+ data.tar.gz: a5a6b4ce5b41f4132d35449840d09650c26d9423505b06ac4171193e3f59ad0cde364ede46abad57c43e4e1c914cb554b38905577bd3ccd6683ebbdcf973a3c7
data/CHANGELOG.md CHANGED
@@ -1,251 +1,273 @@
1
- ## Rails 7.0.8.1 (February 21, 2024) ##
1
+ ## Rails 7.1.3.2 (February 21, 2024) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 7.0.8 (September 09, 2023) ##
7
-
8
- * Fix Active Job log message to correctly report a job failed to enqueue
9
- when the adapter raises an `ActiveJob::EnqueueError`.
10
-
11
- *Ben Sheldon*
12
-
13
-
14
- ## Rails 7.0.7.2 (August 22, 2023) ##
6
+ ## Rails 7.1.3.1 (February 21, 2024) ##
15
7
 
16
8
  * No changes.
17
9
 
18
10
 
19
- ## Rails 7.0.7.1 (August 22, 2023) ##
11
+ ## Rails 7.1.3 (January 16, 2024) ##
20
12
 
21
- * No changes.
13
+ * Do not trigger immediate loading of `ActiveJob::Base` when loading `ActiveJob::TestHelper`.
22
14
 
15
+ *Maxime Réty*
23
16
 
24
- ## Rails 7.0.7 (August 09, 2023) ##
25
-
26
- * No changes.
17
+ * Preserve the serialized timezone when deserializing `ActiveSupport::TimeWithZone` arguments.
27
18
 
19
+ *Joshua Young*
28
20
 
29
- ## Rails 7.0.6 (June 29, 2023) ##
21
+ * Fix ActiveJob arguments serialization to correctly serialize String subclasses having custom serializers.
30
22
 
31
- * Fix error Active Job passed class with `permitted?`.
23
+ *fatkodima*
32
24
 
33
- *Alex Baldwin*
34
25
 
35
-
36
- ## Rails 7.0.5.1 (June 26, 2023) ##
26
+ ## Rails 7.1.2 (November 10, 2023) ##
37
27
 
38
28
  * No changes.
39
29
 
40
30
 
41
- ## Rails 7.0.5 (May 24, 2023) ##
31
+ ## Rails 7.1.1 (October 11, 2023) ##
42
32
 
43
- * Make delayed job `display_name` failsafe.
33
+ * Don't log enqueuing details when the job wasn't enqueued.
44
34
 
45
- *codez*
35
+ *Dustin Brown*
46
36
 
47
- * Don't double log the `job` when using `ActiveRecord::QueryLog`
48
37
 
49
- Previously if you set `config.active_record.query_log_tags` to an array that included
50
- `:job`, the job name would get logged twice. This bug has been fixed.
38
+ ## Rails 7.1.0 (October 05, 2023) ##
51
39
 
52
- *Alex Ghiculescu*
40
+ * No changes.
53
41
 
54
42
 
55
- ## Rails 7.0.4.3 (March 13, 2023) ##
43
+ ## Rails 7.1.0.rc2 (October 01, 2023) ##
56
44
 
57
- * No changes.
45
+ * Make sure `scheduled_at` is a Time object when asserting enqueued jobs.
58
46
 
47
+ *Rafael Mendonça França*
59
48
 
60
- ## Rails 7.0.4.2 (January 24, 2023) ##
61
49
 
62
- * No changes.
50
+ ## Rails 7.1.0.rc1 (September 27, 2023) ##
63
51
 
52
+ * Set `scheduled_at` attribute as a Time object instead of epoch seconds, and serialize and deserialize the value
53
+ when enqueued. Assigning a numeric/epoch value to scheduled_at= is deprecated; use a Time object instead.
64
54
 
65
- ## Rails 7.0.4.1 (January 17, 2023) ##
55
+ Deserializes `enqueued_at` as a Time instead of ISO8601 String.
66
56
 
67
- * No changes.
57
+ *Ben Sheldon*
68
58
 
59
+ * Clarify the backoff strategy for the recommended `:wait` option when retrying jobs
69
60
 
70
- ## Rails 7.0.4 (September 09, 2022) ##
61
+ `wait: :exponentially_longer` is waiting polynomially longer, so it is now recommended to use `wait: :polynomially_longer` to keep the same behavior.
71
62
 
72
- * Update `ActiveJob::QueueAdapters::QueAdapter` to remove deprecation warning.
63
+ *Victor Mours*
73
64
 
74
- Remove a deprecation warning introduced in que 1.2 to prepare for changes in
75
- que 2.0 necessary for Ruby 3 compatibility.
76
65
 
77
- *Damir Zekic* and *Adis Hasovic*
66
+ ## Rails 7.1.0.beta1 (September 13, 2023) ##
78
67
 
79
- ## Rails 7.0.3.1 (July 12, 2022) ##
68
+ * Fix Active Job log message to correctly report a job failed to enqueue
69
+ when the adapter raises an `ActiveJob::EnqueueError`.
80
70
 
81
- * No changes.
71
+ *Ben Sheldon*
82
72
 
73
+ * Add `after_discard` method.
83
74
 
84
- ## Rails 7.0.3 (May 09, 2022) ##
75
+ This method lets job authors define a block which will be run when a job is about to be discarded. For example:
85
76
 
86
- * Add missing `bigdecimal` require in `ActiveJob::Arguments`
77
+ ```ruby
78
+ class AfterDiscardJob < ActiveJob::Base
79
+ after_discard do |job, exception|
80
+ Rails.logger.info("#{job.class} raised an exception: #{exception}")
81
+ end
87
82
 
88
- Could cause `uninitialized constant ActiveJob::Arguments::BigDecimal (NameError)`
89
- when loading Active Job in isolation.
83
+ def perform
84
+ raise StandardError
85
+ end
86
+ end
87
+ ```
90
88
 
91
- *Jean Boussier*
89
+ The above job will run the block passed to `after_discard` after the job is discarded. The exception will
90
+ still be raised after the block has been run.
92
91
 
93
- ## Rails 7.0.2.4 (April 26, 2022) ##
92
+ *Rob Cardy*
94
93
 
95
- * No changes.
94
+ * Fix deserialization of ActiveSupport::Duration
96
95
 
96
+ Previously, a deserialized Duration would return an array from Duration#parts.
97
+ It will now return a hash just like a regular Duration.
97
98
 
98
- ## Rails 7.0.2.3 (March 08, 2022) ##
99
+ This also fixes an error when trying to add or subtract from a deserialized Duration
100
+ (eg `duration + 1.year`).
99
101
 
100
- * No changes.
102
+ *Jonathan del Strother*
101
103
 
104
+ * `perform_enqueued_jobs` is now compatible with all Active Job adapters
102
105
 
103
- ## Rails 7.0.2.2 (February 11, 2022) ##
106
+ This means that methods that depend on it, like Action Mailer's `assert_emails`,
107
+ will work correctly even if the test adapter is not used.
104
108
 
105
- * No changes.
109
+ *Alex Ghiculescu*
106
110
 
111
+ * Allow queue adapters to provide a custom name by implementing `queue_adapter_name`
107
112
 
108
- ## Rails 7.0.2.1 (February 11, 2022) ##
113
+ *Sander Verdonschot*
109
114
 
110
- * No changes.
115
+ * Log background job enqueue callers
111
116
 
117
+ Add `verbose_enqueue_logs` configuration option to display the caller
118
+ of background job enqueue in the log to help with debugging.
112
119
 
113
- ## Rails 7.0.2 (February 08, 2022) ##
120
+ Example log line:
114
121
 
115
- * No changes.
122
+ ```
123
+ Enqueued AvatarThumbnailsJob (Job ID: ab528951-41fb-4c48-9129-3171791c27d6) to Sidekiq(default) with arguments: 1092412064
124
+ ↳ app/models/user.rb:421:in `generate_avatar_thumbnails'
125
+ ```
116
126
 
127
+ Enabled in development only for new and upgraded applications. Not recommended for use
128
+ in the production environment since it relies on Ruby's `Kernel#caller` which is fairly slow.
117
129
 
118
- ## Rails 7.0.1 (January 06, 2022) ##
130
+ *fatkodima*
119
131
 
120
- * Allow testing `discard_on/retry_on ActiveJob::DeserializationError`
132
+ * Set `provider_job_id` for Backburner jobs
121
133
 
122
- Previously in `perform_enqueued_jobs`, `deserialize_arguments_if_needed`
123
- was called before calling `perform_now`. When a record no longer exists
124
- and is serialized using GlobalID this led to raising
125
- an `ActiveJob::DeserializationError` before reaching `perform_now` call.
126
- This behaviour makes difficult testing the job `discard_on/retry_on` logic.
134
+ *Cameron Matheson*
127
135
 
128
- Now `deserialize_arguments_if_needed` call is postponed to when `perform_now`
129
- is called.
136
+ * Add `perform_all_later` to enqueue multiple jobs at once
130
137
 
131
- Example:
138
+ This adds the ability to bulk enqueue jobs, without running callbacks, by
139
+ passing multiple jobs or an array of jobs. For example:
132
140
 
133
141
  ```ruby
134
- class UpdateUserJob < ActiveJob::Base
135
- discard_on ActiveJob::DeserializationError
142
+ ActiveJob.perform_all_later(MyJob.new("hello", 42), MyJob.new("world", 0))
136
143
 
137
- def perform(user)
138
- # ...
139
- end
140
- end
141
-
142
- # In the test
143
- User.destroy_all
144
- assert_nothing_raised do
145
- perform_enqueued_jobs only: UpdateUserJob
146
- end
144
+ user_jobs = User.pluck(:id).map { |id| UserJob.new(user_id: id) }
145
+ ActiveJob.perform_all_later(user_jobs)
147
146
  ```
148
147
 
149
- *Jacopo Beschi*
148
+ This can greatly reduce the number of round-trips to the queue datastore.
149
+ For queue adapters that do not implement the new `enqueue_all` method, we
150
+ fall back to enqueuing jobs individually. The Sidekiq adapter implements
151
+ `enqueue_all` with `push_bulk`.
150
152
 
153
+ This method does not use the existing `enqueue.active_job` event, but adds a
154
+ new event `enqueue_all.active_job`.
151
155
 
152
- ## Rails 7.0.0 (December 15, 2021) ##
153
-
154
- * No changes.
156
+ *Sander Verdonschot*
155
157
 
158
+ * Don't double log the `job` when using `ActiveRecord::QueryLog`
156
159
 
157
- ## Rails 7.0.0.rc3 (December 14, 2021) ##
160
+ Previously if you set `config.active_record.query_log_tags` to an array that included
161
+ `:job`, the job name would get logged twice. This bug has been fixed.
158
162
 
159
- * No changes.
163
+ *Alex Ghiculescu*
160
164
 
165
+ * Add support for Sidekiq's transaction-aware client
161
166
 
162
- ## Rails 7.0.0.rc2 (December 14, 2021) ##
167
+ *Jonathan del Strother*
163
168
 
164
- * No changes.
169
+ * Remove QueAdapter from Active Job.
165
170
 
166
- ## Rails 7.0.0.rc1 (December 06, 2021) ##
171
+ After maintaining Active Job QueAdapter by Rails and Que side
172
+ to support Ruby 3 keyword arguments and options provided as top level keywords,
173
+ it is quite difficult to maintain it this way.
167
174
 
168
- * Remove deprecated `:return_false_on_aborted_enqueue` option.
175
+ Active Job Que adapter can be included in the future version of que gem itself.
169
176
 
170
- *Rafael Mendonça França*
177
+ *Yasuo Honda*
171
178
 
172
- * Deprecated `Rails.config.active_job.skip_after_callbacks_if_terminated`.
179
+ * Fix BigDecimal (de)serialization for adapters using JSON.
173
180
 
174
- *Rafael Mendonça França*
181
+ Previously, BigDecimal was listed as not needing a serializer. However,
182
+ when used with an adapter storing the job arguments as JSON, it would get
183
+ serialized as a simple String, resulting in deserialization also producing
184
+ a String (instead of a BigDecimal).
175
185
 
176
- * Removed deprecated behavior that was not halting `after_enqueue`/`after_perform` callbacks when a
177
- previous callback was halted with `throw :abort`.
186
+ By using a serializer, we ensure the round trip is safe.
178
187
 
179
- *Rafael Mendonça França*
188
+ To ensure applications using BigDecimal job arguments are not subject to
189
+ race conditions during deployment (where a replica running a version of
190
+ Rails without BigDecimalSerializer fails to deserialize an argument
191
+ serialized with it), `ActiveJob.use_big_decimal_serializer` is disabled by
192
+ default, and can be set to true in a following deployment..
180
193
 
181
- * Raise an `SerializationError` in `Serializer::ModuleSerializer`
182
- if the module name is not present.
194
+ *Sam Bostock*
183
195
 
184
- *Veerpal Brar*
196
+ * Preserve full-precision `enqueued_at` timestamps for serialized jobs,
197
+ allowing more accurate reporting of how long a job spent waiting in the
198
+ queue before it was performed.
185
199
 
200
+ Retains IS08601 format compatibility.
186
201
 
187
- ## Rails 7.0.0.alpha2 (September 15, 2021) ##
202
+ *Jeremy Daer*
188
203
 
189
- * No changes.
204
+ * Add `--parent` option to job generator to specify parent class of job.
190
205
 
206
+ Example:
191
207
 
192
- ## Rails 7.0.0.alpha1 (September 15, 2021) ##
208
+ `bin/rails g job process_payment --parent=payment_job` generates:
193
209
 
194
- * Allow a job to retry indefinitely
210
+ ```ruby
211
+ class ProcessPaymentJob < PaymentJob
212
+ # ...
213
+ end
214
+ ```
195
215
 
196
- The `attempts` parameter of the `retry_on` method now accepts the
197
- symbol reference `:unlimited` in addition to a specific number of retry
198
- attempts to allow a developer to specify that a job should retry
199
- forever until it succeeds.
216
+ *Gannon McGibbon*
200
217
 
201
- class MyJob < ActiveJob::Base
202
- retry_on(AlwaysRetryException, attempts: :unlimited)
218
+ * Add more detailed description to job generator.
203
219
 
204
- # the actual job code
205
- end
220
+ *Gannon McGibbon*
206
221
 
207
- *Daniel Morton*
222
+ * `perform.active_job` notification payloads now include `:db_runtime`, which
223
+ is the total time (in ms) taken by database queries while performing a job.
224
+ This value can be used to better understand how a job's time is spent.
208
225
 
209
- * Added possibility to check on `:priority` in test helper methods
210
- `assert_enqueued_with` and `assert_performed_with`.
226
+ *Jonathan Hefner*
211
227
 
212
- *Wojciech Wnętrzak*
228
+ * Update `ActiveJob::QueueAdapters::QueAdapter` to remove deprecation warning.
213
229
 
214
- * OpenSSL constants are now used for Digest computations.
230
+ Remove a deprecation warning introduced in que 1.2 to prepare for changes in
231
+ que 2.0 necessary for Ruby 3 compatibility.
215
232
 
216
- *Dirkjan Bussink*
233
+ *Damir Zekic* and *Adis Hasovic*
217
234
 
218
- * Add a Serializer for the Range class.
235
+ * Add missing `bigdecimal` require in `ActiveJob::Arguments`
219
236
 
220
- This should allow things like `MyJob.perform_later(range: 1..100)`.
237
+ Could cause `uninitialized constant ActiveJob::Arguments::BigDecimal (NameError)`
238
+ when loading Active Job in isolation.
221
239
 
222
- * Communicate enqueue failures to callers of `perform_later`.
240
+ *Jean Boussier*
223
241
 
224
- `perform_later` can now optionally take a block which will execute after
225
- the adapter attempts to enqueue the job. The block will receive the job
226
- instance as an argument even if the enqueue was not successful.
227
- Additionally, `ActiveJob` adapters now have the ability to raise an
228
- `ActiveJob::EnqueueError` which will be caught and stored in the job
229
- instance so code attempting to enqueue jobs can inspect any raised
230
- `EnqueueError` using the block.
242
+ * Allow testing `discard_on/retry_on ActiveJob::DeserializationError`
231
243
 
232
- MyJob.perform_later do |job|
233
- unless job.successfully_enqueued?
234
- if job.enqueue_error&.message == "Redis was unavailable"
235
- # invoke some code that will retry the job after a delay
236
- end
237
- end
238
- end
244
+ Previously in `perform_enqueued_jobs`, `deserialize_arguments_if_needed`
245
+ was called before calling `perform_now`. When a record no longer exists
246
+ and is serialized using GlobalID this led to raising
247
+ an `ActiveJob::DeserializationError` before reaching `perform_now` call.
248
+ This behavior makes difficult testing the job `discard_on/retry_on` logic.
239
249
 
240
- *Daniel Morton*
250
+ Now `deserialize_arguments_if_needed` call is postponed to when `perform_now`
251
+ is called.
241
252
 
242
- * Don't log rescuable exceptions defined with `rescue_from`.
253
+ Example:
243
254
 
244
- *Hu Hailin*
255
+ ```ruby
256
+ class UpdateUserJob < ActiveJob::Base
257
+ discard_on ActiveJob::DeserializationError
245
258
 
246
- * Allow `rescue_from` to rescue all exceptions.
259
+ def perform(user)
260
+ # ...
261
+ end
262
+ end
247
263
 
248
- *Adrianna Chang*, *Étienne Barrié*
264
+ # In the test
265
+ User.destroy_all
266
+ assert_nothing_raised do
267
+ perform_enqueued_jobs only: UpdateUserJob
268
+ end
269
+ ```
249
270
 
271
+ *Jacopo Beschi*
250
272
 
251
- Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activejob/CHANGELOG.md) for previous changes.
273
+ Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/activejob/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2022 David Heinemeier Hansson
1
+ Copyright (c) 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
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://edgeguides.rubyonrails.org/active_job_basics.html) guide.
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
 
@@ -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 :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY,
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 *PERMITTED_TYPES
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,29 @@ 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
- Serializers.serialize(argument)
102
+ if argument.respond_to?(:permitted?) && argument.respond_to?(:to_h)
103
+ serialize_indifferent_hash(argument.to_h)
104
+ elsif BigDecimal === argument && !ActiveJob.use_big_decimal_serializer
105
+ ActiveJob.deprecator.warn(<<~MSG)
106
+ Primitive serialization of BigDecimal job arguments is deprecated as it may serialize via .to_s using certain queue adapters.
107
+ Enable config.active_job.use_big_decimal_serializer to use BigDecimalSerializer instead, which will be mandatory in Rails 7.2.
108
+
109
+ Note that if your application has multiple replicas, you should only enable this setting after successfully deploying your app to Rails 7.1 first.
110
+ This will ensure that during your deployment all replicas are capable of deserializing arguments serialized with BigDecimalSerializer.
111
+ MSG
112
+ argument
113
+ else
114
+ Serializers.serialize(argument)
115
+ end
119
116
  end
120
117
  end
121
118
 
122
119
  def deserialize_argument(argument)
123
120
  case argument
124
- when String
121
+ when nil, true, false, String, Integer, Float
125
122
  argument
126
- when *PERMITTED_TYPES
123
+ when BigDecimal # BigDecimal may have been legacy serialized; Remove in 7.2
127
124
  argument
128
125
  when Array
129
126
  argument.map { |arg| deserialize_argument(arg) }
@@ -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:
@@ -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
@@ -135,7 +132,8 @@ module ActiveJob
135
132
  # queue_as :default
136
133
  #
137
134
  # after_enqueue do |job|
138
- # $statsd.increment "enqueue-video-job.success"
135
+ # result = job.successfully_enqueued? ? "success" : "failure"
136
+ # $statsd.increment "enqueue-video-job.#{result}"
139
137
  # end
140
138
  #
141
139
  # def perform(video_id)
@@ -14,5 +14,9 @@ module ActiveJob
14
14
  def perform_later(...)
15
15
  @job_class.new(...).enqueue @options
16
16
  end
17
+
18
+ def perform_all_later(multi_args)
19
+ @job_class.perform_all_later(multi_args, options: @options)
20
+ end
17
21
  end
18
22
  end
@@ -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
- # Timestamp when the job should be performed
14
- attr_accessor :scheduled_at
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.to_f if options[:wait]
162
- self.scheduled_at = options[:wait_until].to_f if 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?