activejob 5.2.8.1 → 6.1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +118 -57
  3. data/MIT-LICENSE +1 -2
  4. data/README.md +18 -13
  5. data/lib/active_job/arguments.rb +80 -30
  6. data/lib/active_job/base.rb +6 -1
  7. data/lib/active_job/callbacks.rb +46 -3
  8. data/lib/active_job/configured_job.rb +2 -0
  9. data/lib/active_job/core.rb +40 -21
  10. data/lib/active_job/enqueuing.rb +20 -7
  11. data/lib/active_job/exceptions.rb +60 -28
  12. data/lib/active_job/execution.rb +11 -2
  13. data/lib/active_job/gem_version.rb +3 -3
  14. data/lib/active_job/instrumentation.rb +40 -0
  15. data/lib/active_job/log_subscriber.rb +140 -0
  16. data/lib/active_job/logging.rb +3 -101
  17. data/lib/active_job/queue_adapter.rb +5 -0
  18. data/lib/active_job/queue_adapters/async_adapter.rb +1 -1
  19. data/lib/active_job/queue_adapters/backburner_adapter.rb +2 -2
  20. data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
  21. data/lib/active_job/queue_adapters/que_adapter.rb +2 -2
  22. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +2 -2
  23. data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +1 -1
  24. data/lib/active_job/queue_adapters/test_adapter.rb +32 -14
  25. data/lib/active_job/queue_adapters.rb +13 -11
  26. data/lib/active_job/queue_name.rb +23 -3
  27. data/lib/active_job/railtie.rb +20 -1
  28. data/lib/active_job/serializers/date_serializer.rb +20 -0
  29. data/lib/active_job/serializers/date_time_serializer.rb +16 -0
  30. data/lib/active_job/serializers/duration_serializer.rb +23 -0
  31. data/lib/active_job/serializers/module_serializer.rb +20 -0
  32. data/lib/active_job/serializers/object_serializer.rb +53 -0
  33. data/lib/active_job/serializers/symbol_serializer.rb +20 -0
  34. data/lib/active_job/serializers/time_object_serializer.rb +13 -0
  35. data/lib/active_job/serializers/time_serializer.rb +16 -0
  36. data/lib/active_job/serializers/time_with_zone_serializer.rb +16 -0
  37. data/lib/active_job/serializers.rb +66 -0
  38. data/lib/active_job/test_helper.rb +317 -68
  39. data/lib/active_job/timezones.rb +13 -0
  40. data/lib/active_job/translation.rb +1 -1
  41. data/lib/active_job.rb +2 -1
  42. data/lib/rails/generators/job/job_generator.rb +4 -0
  43. metadata +25 -9
  44. data/lib/active_job/queue_adapters/qu_adapter.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da2404a4773487b6302f696114ebfc6e461481ac51abba4adcdb169fa7df2f9c
4
- data.tar.gz: 371b96928991144d2d6e5880eedecc8959d78975aad4da78c71c7e790752317f
3
+ metadata.gz: 071e17ba1697758131ad5d4b52b8fb75bd5524223ab09df4514cc141063d1433
4
+ data.tar.gz: cb88712ddaf62636cc3433f2dfc6045ff7a47eca8f637a7ecb733b1d0e4ca09e
5
5
  SHA512:
6
- metadata.gz: 86113704b57cd7ab3d3b4bcd411c104376cf9c453e285277f018e5d537492a4e9eaa41f417ef495f4b6f84be94867adad2d5306f01ff49bf5aeacd47583cbe40
7
- data.tar.gz: d971688295936bc31b1c2cc5c2bd611601598e9d9a3a9b9fa0c221d23bf61b88e76381c29398d20c751fec1333f4c37f78c58921e1d532af2b7f3a505dba7af4
6
+ metadata.gz: cae13680a6e83ba16396f21d423d86165b47d14ef9f612c9b84247dc0c3f560ff29f797e1cf016a8c239df80fdbcc48273fc3ff4fa6d5c3d67af8afd9ee7afec
7
+ data.tar.gz: 5bedff1cb072d30760c81ab99e2495ea88bc78b42f731a88500c90ff6321a063882237ed3f52f57b01a85deae825a97b471ad8f5ce58a3197f24a9af924ba499
data/CHANGELOG.md CHANGED
@@ -1,160 +1,221 @@
1
- ## Rails 5.2.8.1 (July 12, 2022) ##
1
+ ## Rails 6.1.6.1 (July 12, 2022) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 5.2.8 (May 09, 2022) ##
6
+ ## Rails 6.1.5.1 (April 26, 2022) ##
7
7
 
8
8
  * No changes.
9
9
 
10
10
 
11
- ## Rails 5.2.7.1 (April 26, 2022) ##
11
+ ## Rails 6.1.5 (March 09, 2022) ##
12
12
 
13
13
  * No changes.
14
14
 
15
15
 
16
- ## Rails 5.2.7 (March 10, 2022) ##
16
+ ## Rails 6.1.4.7 (March 08, 2022) ##
17
17
 
18
18
  * No changes.
19
19
 
20
20
 
21
- ## Rails 5.2.6.3 (March 08, 2022) ##
21
+ ## Rails 6.1.4.6 (February 11, 2022) ##
22
22
 
23
23
  * No changes.
24
24
 
25
25
 
26
- ## Rails 5.2.6.2 (February 11, 2022) ##
26
+ ## Rails 6.1.4.5 (February 11, 2022) ##
27
27
 
28
28
  * No changes.
29
29
 
30
30
 
31
- ## Rails 5.2.6.1 (February 11, 2022) ##
31
+ ## Rails 6.1.4.4 (December 15, 2021) ##
32
32
 
33
33
  * No changes.
34
34
 
35
35
 
36
- ## Rails 5.2.6 (May 05, 2021) ##
36
+ ## Rails 6.1.4.3 (December 14, 2021) ##
37
37
 
38
38
  * No changes.
39
39
 
40
40
 
41
- ## Rails 5.2.5 (March 26, 2021) ##
41
+ ## Rails 6.1.4.2 (December 14, 2021) ##
42
42
 
43
43
  * No changes.
44
44
 
45
45
 
46
- ## Rails 5.2.4.6 (May 05, 2021) ##
46
+ ## Rails 6.1.4.1 (August 19, 2021) ##
47
47
 
48
48
  * No changes.
49
49
 
50
50
 
51
- ## Rails 5.2.4.5 (February 10, 2021) ##
51
+ ## Rails 6.1.4 (June 24, 2021) ##
52
52
 
53
53
  * No changes.
54
54
 
55
55
 
56
- ## Rails 5.2.4.4 (September 09, 2020) ##
56
+ ## Rails 6.1.3.2 (May 05, 2021) ##
57
57
 
58
58
  * No changes.
59
59
 
60
60
 
61
- ## Rails 5.2.4.3 (May 18, 2020) ##
61
+ ## Rails 6.1.3.1 (March 26, 2021) ##
62
62
 
63
63
  * No changes.
64
64
 
65
65
 
66
- ## Rails 5.2.4.2 (March 19, 2020) ##
66
+ ## Rails 6.1.3 (February 17, 2021) ##
67
67
 
68
68
  * No changes.
69
69
 
70
70
 
71
- ## Rails 5.2.4.1 (December 18, 2019) ##
71
+ ## Rails 6.1.2.1 (February 10, 2021) ##
72
72
 
73
73
  * No changes.
74
74
 
75
75
 
76
- ## Rails 5.2.4 (November 27, 2019) ##
76
+ ## Rails 6.1.2 (February 09, 2021) ##
77
77
 
78
78
  * No changes.
79
79
 
80
80
 
81
- ## Rails 5.2.3 (March 27, 2019) ##
81
+ ## Rails 6.1.1 (January 07, 2021) ##
82
82
 
83
- * No changes.
83
+ * Make `retry_job` return the job that was created.
84
84
 
85
+ *Rafael Mendonça França*
85
86
 
86
- ## Rails 5.2.2.1 (March 11, 2019) ##
87
+ * Include `ActiveSupport::Testing::Assertions` in `ActiveJob::TestHelpers`.
87
88
 
88
- * No changes.
89
+ *Mikkel Malmberg*
89
90
 
90
91
 
91
- ## Rails 5.2.2 (December 04, 2018) ##
92
+ ## Rails 6.1.0 (December 09, 2020) ##
92
93
 
93
- * Make sure `assert_enqueued_with()` & `assert_performed_with()` work reliably with hash arguments.
94
+ * Recover nano precision when serializing `Time`, `TimeWithZone` and `DateTime` objects.
94
95
 
95
- *Sharang Dashputre*
96
+ *Alan Tan*
96
97
 
97
- * Restore `ActionController::Parameters` support to `ActiveJob::Arguments.serialize`.
98
+ * Deprecate `config.active_job.return_false_on_aborted_enqueue`.
98
99
 
99
- *Bernie Chiu*
100
+ *Rafael Mendonça França*
100
101
 
101
- * Restore `HashWithIndifferentAccess` support to `ActiveJob::Arguments.deserialize`.
102
+ * Return `false` when enqueuing a job is aborted.
102
103
 
103
- *Gannon McGibbon*
104
+ *Rafael Mendonça França*
104
105
 
105
- * Include deserialized arguments in job instances returned from
106
- `assert_enqueued_with` and `assert_performed_with`
106
+ * While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
107
+ `assert_enqueued_with`.
107
108
 
108
- *Alan Wu*
109
+ *Dmitry Polushkin*
109
110
 
110
- * Increment execution count before deserialize arguments.
111
+ * `ActiveJob::TestCase#perform_enqueued_jobs` without a block removes performed jobs from the queue.
111
112
 
112
- Currently, the execution count increments after deserializes arguments.
113
- Therefore, if an error occurs with deserialize, it retries indefinitely.
113
+ That way the helper can be called multiple times and not perform a job invocation multiple times.
114
114
 
115
- *Yuji Yaginuma*
115
+ ```ruby
116
+ def test_jobs
117
+ HelloJob.perform_later("rafael")
118
+ perform_enqueued_jobs # only runs with "rafael"
119
+ HelloJob.perform_later("david")
120
+ perform_enqueued_jobs # only runs with "david"
121
+ end
122
+ ```
116
123
 
124
+ *Étienne Barrié*
117
125
 
118
- ## Rails 5.2.1.1 (November 27, 2018) ##
126
+ * `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
119
127
 
120
- * Do not deserialize GlobalID objects that were not generated by Active Job.
128
+ When calling `perform_enqueued_jobs` without a block, the adapter will
129
+ now perform jobs that are **already** in the queue. Jobs that will end up in
130
+ the queue afterwards won't be performed.
121
131
 
122
- Trusting any GlobaID object when deserializing jobs can allow attackers to access
123
- information that should not be accessible to them.
132
+ This change only affects `perform_enqueued_jobs` when no block is given.
124
133
 
125
- Fix CVE-2018-16476.
134
+ *Edouard Chin*
126
135
 
127
- *Rafael Mendonça França*
136
+ * Add queue name support to Que adapter.
137
+
138
+ *Brad Nauta*, *Wojciech Wnętrzak*
128
139
 
140
+ * Don't run `after_enqueue` and `after_perform` callbacks if the callback chain is halted.
129
141
 
130
- ## Rails 5.2.1 (August 07, 2018) ##
142
+ class MyJob < ApplicationJob
143
+ before_enqueue { throw(:abort) }
144
+ after_enqueue { # won't enter here anymore }
145
+ end
131
146
 
132
- * Pass the error instance as the second parameter of block executed by `discard_on`.
147
+ `after_enqueue` and `after_perform` callbacks will no longer run if the callback chain is halted.
148
+ This behaviour is a breaking change and won't take effect until Rails 7.0.
149
+ To enable this behaviour in your app right now, you can add in your app's configuration file
150
+ `config.active_job.skip_after_callbacks_if_terminated = true`.
133
151
 
134
- Fixes #32853.
152
+ *Edouard Chin*
135
153
 
136
- *Yuji Yaginuma*
154
+ * Fix enqueuing and performing incorrect logging message.
137
155
 
138
- ## Rails 5.2.0 (April 09, 2018) ##
156
+ Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
139
157
 
140
- * Allow block to be passed to `ActiveJob::Base.discard_on` to allow custom handling of discard jobs.
158
+ ```ruby
159
+ class MyJob < ApplicationJob
160
+ before_enqueue { throw(:abort) }
161
+ end
141
162
 
142
- Example:
163
+ MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.
164
+ ```
143
165
 
144
- class RemoteServiceJob < ActiveJob::Base
145
- discard_on(CustomAppException) do |job, exception|
146
- ExceptionNotifier.caught(exception)
147
- end
166
+ A new message will be logged in case a job couldn't be enqueued, either because the callback chain was halted or
167
+ because an exception happened during enqueuing. (i.e. Redis is down when you try to enqueue your job)
168
+
169
+ *Edouard Chin*
170
+
171
+ * Add an option to disable logging of the job arguments when enqueuing and executing the job.
148
172
 
149
- def perform(*args)
150
- # Might raise CustomAppException for something domain specific
173
+ class SensitiveJob < ApplicationJob
174
+ self.log_arguments = false
175
+
176
+ def perform(my_sensitive_argument)
151
177
  end
152
178
  end
153
179
 
154
- *Aidan Haran*
180
+ When dealing with sensitive arguments as password and tokens it is now possible to configure the job
181
+ to not put the sensitive argument in the logs.
182
+
183
+ *Rafael Mendonça França*
184
+
185
+ * Changes in `queue_name_prefix` of a job no longer affects all other jobs.
186
+
187
+ Fixes #37084.
188
+
189
+ *Lucas Mansur*
190
+
191
+ * Allow `Class` and `Module` instances to be serialized.
192
+
193
+ *Kevin Deisz*
194
+
195
+ * Log potential matches in `assert_enqueued_with` and `assert_performed_with`.
196
+
197
+ *Gareth du Plooy*
198
+
199
+ * Add `at` argument to the `perform_enqueued_jobs` test helper.
200
+
201
+ *John Crepezzi*, *Eileen Uchitelle*
202
+
203
+ * `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
204
+
205
+ *Vlado Cingel*
206
+
207
+ * Add jitter to `ActiveJob::Exceptions.retry_on`.
208
+
209
+ `ActiveJob::Exceptions.retry_on` now uses a random amount of jitter in order to
210
+ prevent the [thundering herd effect](https://en.wikipedia.org/wiki/Thundering_herd_problem). Defaults to
211
+ 15% (represented as 0.15) but overridable via the `:jitter` option when using `retry_on`.
212
+ Jitter is applied when an `Integer`, `ActiveSupport::Duration` or `:exponentially_longer`, is passed to the `wait` argument in `retry_on`.
213
+
214
+ ```ruby
215
+ retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)
216
+ ```
155
217
 
156
- * Support redis-rb 4.0.
218
+ *Anthony Ross*
157
219
 
158
- *Jeremy Daer*
159
220
 
160
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md) for previous changes.
221
+ 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-2018 David Heinemeier Hansson
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
@@ -1,7 +1,7 @@
1
- # Active Job -- Make work happen later
1
+ # Active Job Make work happen later
2
2
 
3
3
  Active Job is a framework for declaring jobs and making them run on a variety
4
- of queueing backends. These jobs can be everything from regularly scheduled
4
+ of queuing backends. These jobs can be everything from regularly scheduled
5
5
  clean-ups, to billing charges, to mailings. Anything that can be chopped up into
6
6
  small units of work and run in parallel, really.
7
7
 
@@ -17,12 +17,13 @@ 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
21
 
21
22
  ## Usage
22
23
 
23
- To learn how to use your preferred queueing backend see its adapter
24
+ To learn how to use your preferred queuing backend see its adapter
24
25
  documentation at
25
- [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
26
+ [ActiveJob::QueueAdapters](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
26
27
 
27
28
  Declare a job like so:
28
29
 
@@ -39,7 +40,7 @@ end
39
40
  Enqueue a job like so:
40
41
 
41
42
  ```ruby
42
- MyJob.perform_later record # Enqueue a job to be performed as soon as the queueing system is free.
43
+ MyJob.perform_later record # Enqueue a job to be performed as soon as the queuing system is free.
43
44
  ```
44
45
 
45
46
  ```ruby
@@ -82,15 +83,18 @@ This works with any class that mixes in GlobalID::Identification, which
82
83
  by default has been mixed into Active Record classes.
83
84
 
84
85
 
85
- ## Supported queueing systems
86
+ ## Supported queuing systems
86
87
 
87
- Active Job has built-in adapters for multiple queueing backends (Sidekiq,
88
+ Active Job has built-in adapters for multiple queuing backends (Sidekiq,
88
89
  Resque, Delayed Job and others). To get an up-to-date list of the adapters
89
- see the API Documentation for [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
90
+ see the API Documentation for [ActiveJob::QueueAdapters](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
90
91
 
91
- ## Auxiliary gems
92
+ **Please note:** We are not accepting pull requests for new adapters. We
93
+ encourage library authors to provide an ActiveJob adapter as part of
94
+ their gem, or as a stand-alone gem. For discussion about this see the
95
+ following PRs: [23311](https://github.com/rails/rails/issues/23311#issuecomment-176275718),
96
+ [21406](https://github.com/rails/rails/pull/21406#issuecomment-138813484), and [#32285](https://github.com/rails/rails/pull/32285).
92
97
 
93
- * [activejob-stats](https://github.com/seuros/activejob-stats)
94
98
 
95
99
  ## Download and installation
96
100
 
@@ -102,7 +106,8 @@ The latest version of Active Job can be installed with RubyGems:
102
106
 
103
107
  Source code can be downloaded as part of the Rails project on GitHub:
104
108
 
105
- * https://github.com/rails/rails/tree/5-2-stable/activejob
109
+ * https://github.com/rails/rails/tree/main/activejob
110
+
106
111
 
107
112
  ## License
108
113
 
@@ -115,7 +120,7 @@ Active Job is released under the MIT license:
115
120
 
116
121
  API documentation is at:
117
122
 
118
- * http://api.rubyonrails.org
123
+ * https://api.rubyonrails.org
119
124
 
120
125
  Bug reports for the Ruby on Rails project can be filed here:
121
126
 
@@ -123,4 +128,4 @@ Bug reports for the Ruby on Rails project can be filed here:
123
128
 
124
129
  Feature requests should be discussed on the rails-core mailing list here:
125
130
 
126
- * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
131
+ * https://discuss.rubyonrails.org/c/rubyonrails-core
@@ -14,29 +14,30 @@ module ActiveJob
14
14
  end
15
15
 
16
16
  # Raised when an unsupported argument type is set as a job argument. We
17
- # currently support NilClass, Integer, Fixnum, Float, String, TrueClass, FalseClass,
18
- # Bignum, BigDecimal, and objects that can be represented as GlobalIDs (ex: Active Record).
17
+ # currently support String, Integer, Float, NilClass, TrueClass, FalseClass,
18
+ # BigDecimal, Symbol, Date, Time, DateTime, ActiveSupport::TimeWithZone,
19
+ # ActiveSupport::Duration, Hash, ActiveSupport::HashWithIndifferentAccess,
20
+ # Array or GlobalID::Identification instances, although this can be extended
21
+ # by adding custom serializers.
19
22
  # Raised if you set the key for a Hash something else than a string or
20
23
  # a symbol. Also raised when trying to serialize an object which can't be
21
- # identified with a Global ID - such as an unpersisted Active Record model.
24
+ # identified with a GlobalID - such as an unpersisted Active Record model.
22
25
  class SerializationError < ArgumentError; end
23
26
 
24
27
  module Arguments
25
28
  extend self
26
- # :nodoc:
27
- TYPE_WHITELIST = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
28
- TYPE_WHITELIST.push(Fixnum, Bignum) unless 1.class == Integer
29
-
30
- # Serializes a set of arguments. Whitelisted types are returned
31
- # as-is. Arrays/Hashes are serialized element by element.
32
- # All other types are serialized using GlobalID.
29
+ # Serializes a set of arguments. Intrinsic types that can safely be
30
+ # serialized without mutation are returned as-is. Arrays/Hashes are
31
+ # serialized element by element. All other types are serialized using
32
+ # GlobalID.
33
33
  def serialize(arguments)
34
34
  arguments.map { |argument| serialize_argument(argument) }
35
35
  end
36
36
 
37
- # Deserializes a set of arguments. Whitelisted types are returned
38
- # as-is. Arrays/Hashes are deserialized element by element.
39
- # All other types are deserialized using GlobalID.
37
+ # Deserializes a set of arguments. Intrinsic types that can safely be
38
+ # deserialized without mutation are returned as-is. Arrays/Hashes are
39
+ # deserialized element by element. All other types are deserialized using
40
+ # GlobalID.
40
41
  def deserialize(arguments)
41
42
  arguments.map { |argument| deserialize_argument(argument) }
42
43
  rescue
@@ -45,16 +46,59 @@ module ActiveJob
45
46
 
46
47
  private
47
48
  # :nodoc:
48
- GLOBALID_KEY = "_aj_globalid".freeze
49
+ PERMITTED_TYPES = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
50
+ # :nodoc:
51
+ GLOBALID_KEY = "_aj_globalid"
52
+ # :nodoc:
53
+ SYMBOL_KEYS_KEY = "_aj_symbol_keys"
54
+ # :nodoc:
55
+ RUBY2_KEYWORDS_KEY = "_aj_ruby2_keywords"
49
56
  # :nodoc:
50
- SYMBOL_KEYS_KEY = "_aj_symbol_keys".freeze
57
+ WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access"
51
58
  # :nodoc:
52
- WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access".freeze
53
- private_constant :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
59
+ OBJECT_SERIALIZER_KEY = "_aj_serialized"
60
+
61
+ # :nodoc:
62
+ RESERVED_KEYS = [
63
+ GLOBALID_KEY, GLOBALID_KEY.to_sym,
64
+ SYMBOL_KEYS_KEY, SYMBOL_KEYS_KEY.to_sym,
65
+ RUBY2_KEYWORDS_KEY, RUBY2_KEYWORDS_KEY.to_sym,
66
+ OBJECT_SERIALIZER_KEY, OBJECT_SERIALIZER_KEY.to_sym,
67
+ WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
68
+ ]
69
+ private_constant :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY,
70
+ :SYMBOL_KEYS_KEY, :RUBY2_KEYWORDS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
71
+
72
+ unless Hash.respond_to?(:ruby2_keywords_hash?) && Hash.respond_to?(:ruby2_keywords_hash)
73
+ using Module.new {
74
+ refine Hash do
75
+ class << Hash
76
+ if RUBY_VERSION >= "2.7"
77
+ def ruby2_keywords_hash?(hash)
78
+ !new(*[hash]).default.equal?(hash)
79
+ end
80
+ else
81
+ def ruby2_keywords_hash?(hash)
82
+ false
83
+ end
84
+ end
85
+
86
+ def ruby2_keywords_hash(hash)
87
+ _ruby2_keywords_hash(**hash)
88
+ end
89
+
90
+ private def _ruby2_keywords_hash(*args)
91
+ args.last
92
+ end
93
+ ruby2_keywords(:_ruby2_keywords_hash) if respond_to?(:ruby2_keywords, true)
94
+ end
95
+ end
96
+ }
97
+ end
54
98
 
55
99
  def serialize_argument(argument)
56
100
  case argument
57
- when *TYPE_WHITELIST
101
+ when *PERMITTED_TYPES
58
102
  argument
59
103
  when GlobalID::Identification
60
104
  convert_to_global_id_hash(argument)
@@ -63,14 +107,19 @@ module ActiveJob
63
107
  when ActiveSupport::HashWithIndifferentAccess
64
108
  serialize_indifferent_hash(argument)
65
109
  when Hash
66
- symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
110
+ symbol_keys = argument.each_key.grep(Symbol).map!(&:to_s)
111
+ aj_hash_key = if Hash.ruby2_keywords_hash?(argument)
112
+ RUBY2_KEYWORDS_KEY
113
+ else
114
+ SYMBOL_KEYS_KEY
115
+ end
67
116
  result = serialize_hash(argument)
68
- result[SYMBOL_KEYS_KEY] = symbol_keys
117
+ result[aj_hash_key] = symbol_keys
69
118
  result
70
119
  when -> (arg) { arg.respond_to?(:permitted?) }
71
120
  serialize_indifferent_hash(argument.to_h)
72
121
  else
73
- raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
122
+ Serializers.serialize(argument)
74
123
  end
75
124
  end
76
125
 
@@ -78,13 +127,15 @@ module ActiveJob
78
127
  case argument
79
128
  when String
80
129
  argument
81
- when *TYPE_WHITELIST
130
+ when *PERMITTED_TYPES
82
131
  argument
83
132
  when Array
84
133
  argument.map { |arg| deserialize_argument(arg) }
85
134
  when Hash
86
135
  if serialized_global_id?(argument)
87
136
  deserialize_global_id argument
137
+ elsif custom_serialized?(argument)
138
+ Serializers.deserialize(argument)
88
139
  else
89
140
  deserialize_hash(argument)
90
141
  end
@@ -101,6 +152,10 @@ module ActiveJob
101
152
  GlobalID::Locator.locate hash[GLOBALID_KEY]
102
153
  end
103
154
 
155
+ def custom_serialized?(hash)
156
+ hash.key?(OBJECT_SERIALIZER_KEY)
157
+ end
158
+
104
159
  def serialize_hash(argument)
105
160
  argument.each_with_object({}) do |(key, value), hash|
106
161
  hash[serialize_hash_key(key)] = serialize_argument(value)
@@ -113,18 +168,13 @@ module ActiveJob
113
168
  result = result.with_indifferent_access
114
169
  elsif symbol_keys = result.delete(SYMBOL_KEYS_KEY)
115
170
  result = transform_symbol_keys(result, symbol_keys)
171
+ elsif symbol_keys = result.delete(RUBY2_KEYWORDS_KEY)
172
+ result = transform_symbol_keys(result, symbol_keys)
173
+ result = Hash.ruby2_keywords_hash(result)
116
174
  end
117
175
  result
118
176
  end
119
177
 
120
- # :nodoc:
121
- RESERVED_KEYS = [
122
- GLOBALID_KEY, GLOBALID_KEY.to_sym,
123
- SYMBOL_KEYS_KEY, SYMBOL_KEYS_KEY.to_sym,
124
- WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
125
- ]
126
- private_constant :RESERVED_KEYS
127
-
128
178
  def serialize_hash_key(key)
129
179
  case key
130
180
  when *RESERVED_KEYS
@@ -8,7 +8,10 @@ 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"
14
+ require "active_job/timezones"
12
15
  require "active_job/translation"
13
16
 
14
17
  module ActiveJob #:nodoc:
@@ -39,7 +42,7 @@ module ActiveJob #:nodoc:
39
42
  # Records that are passed in are serialized/deserialized using Global
40
43
  # ID. More information can be found in Arguments.
41
44
  #
42
- # To enqueue a job to be performed as soon as the queueing system is free:
45
+ # To enqueue a job to be performed as soon as the queuing system is free:
43
46
  #
44
47
  # ProcessPhotoJob.perform_later(photo)
45
48
  #
@@ -67,6 +70,8 @@ module ActiveJob #:nodoc:
67
70
  include Callbacks
68
71
  include Exceptions
69
72
  include Logging
73
+ include Instrumentation
74
+ include Timezones
70
75
  include Translation
71
76
 
72
77
  ActiveSupport.run_load_hooks(:active_job, self)