activejob 5.2.4.4 → 6.1.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 +91 -50
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +18 -13
  5. data/lib/active_job.rb +2 -1
  6. data/lib/active_job/arguments.rb +80 -30
  7. data/lib/active_job/base.rb +6 -1
  8. data/lib/active_job/callbacks.rb +46 -3
  9. data/lib/active_job/configured_job.rb +2 -0
  10. data/lib/active_job/core.rb +40 -21
  11. data/lib/active_job/enqueuing.rb +20 -7
  12. data/lib/active_job/exceptions.rb +60 -28
  13. data/lib/active_job/execution.rb +11 -2
  14. data/lib/active_job/gem_version.rb +4 -4
  15. data/lib/active_job/instrumentation.rb +40 -0
  16. data/lib/active_job/log_subscriber.rb +140 -0
  17. data/lib/active_job/logging.rb +3 -101
  18. data/lib/active_job/queue_adapter.rb +5 -0
  19. data/lib/active_job/queue_adapters.rb +13 -11
  20. data/lib/active_job/queue_adapters/async_adapter.rb +1 -1
  21. data/lib/active_job/queue_adapters/backburner_adapter.rb +2 -2
  22. data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
  23. data/lib/active_job/queue_adapters/que_adapter.rb +2 -2
  24. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +2 -2
  25. data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +1 -1
  26. data/lib/active_job/queue_adapters/test_adapter.rb +32 -14
  27. data/lib/active_job/queue_name.rb +23 -3
  28. data/lib/active_job/railtie.rb +20 -1
  29. data/lib/active_job/serializers.rb +66 -0
  30. data/lib/active_job/serializers/date_serializer.rb +20 -0
  31. data/lib/active_job/serializers/date_time_serializer.rb +16 -0
  32. data/lib/active_job/serializers/duration_serializer.rb +23 -0
  33. data/lib/active_job/serializers/module_serializer.rb +20 -0
  34. data/lib/active_job/serializers/object_serializer.rb +53 -0
  35. data/lib/active_job/serializers/symbol_serializer.rb +20 -0
  36. data/lib/active_job/serializers/time_object_serializer.rb +13 -0
  37. data/lib/active_job/serializers/time_serializer.rb +16 -0
  38. data/lib/active_job/serializers/time_with_zone_serializer.rb +16 -0
  39. data/lib/active_job/test_helper.rb +316 -68
  40. data/lib/active_job/timezones.rb +13 -0
  41. data/lib/active_job/translation.rb +1 -1
  42. data/lib/rails/generators/job/job_generator.rb +4 -0
  43. metadata +29 -14
  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: 579058f1d7a36f41a5520a6b0407313b2239feba0a4650cb8d4de7c26944bb22
4
- data.tar.gz: 6ff97713a73eeda521f8e2ac92b57e3307cc5fcb70192b52e30c4f41792b093d
3
+ metadata.gz: 35320cc54085adaeb2a5cdc283c0287992945e520ec24f2f6eb68690abe7f2c2
4
+ data.tar.gz: 26aa5b5976bb96e5571a66464b3d25d239a1197167b87a2673c33e67ded91013
5
5
  SHA512:
6
- metadata.gz: 9cd80bb282fa4dc6078af56863c27484464fd4ef2d0656cf6886e861ed2e03415a7ff158c16313147fcef3782e434277b514ed6e138b378ed0677044250467be
7
- data.tar.gz: f1235b757475555ed035b5f340a2fec95168209ce031ddfd65d81f020e661240636611f1f3f15453b9e097036c50612adc23dbd0aace1cec6f0468e716419a29
6
+ metadata.gz: 6cf40eaaa0a1b5003bdecaecd29a5deb1060998f405677fd1114599fcc95285d1173c2da125f3e5f3557e2773a71a77e49919e39b67a6cd8cdeeb01db37db48b
7
+ data.tar.gz: aca36b4e3c1348d096dcd9f8e033f18705f648d5f3d092e9a6882b9fd8c6a24bc322bd417d0792c9f7af5c8bebb277250e5c552fdb8b2fce946a0cfefb671888
data/CHANGELOG.md CHANGED
@@ -1,100 +1,141 @@
1
- ## Rails 5.2.4.4 (September 09, 2020) ##
1
+ ## Rails 6.1.1 (January 07, 2021) ##
2
2
 
3
- * No changes.
3
+ * Make `retry_job` return the job that was created.
4
+
5
+ *Rafael Mendonça França*
6
+
7
+ * Include `ActiveSupport::Testing::Assertions` in `ActiveJob::TestHelpers`.
8
+
9
+ *Mikkel Malmberg*
4
10
 
5
11
 
6
- ## Rails 5.2.4.3 (May 18, 2020) ##
12
+ ## Rails 6.1.0 (December 09, 2020) ##
7
13
 
8
- * No changes.
14
+ * Recover nano precision when serializing `Time`, `TimeWithZone` and `DateTime` objects.
9
15
 
16
+ *Alan Tan*
10
17
 
11
- ## Rails 5.2.4.1 (December 18, 2019) ##
18
+ * Deprecate `config.active_job.return_false_on_aborted_enqueue`.
12
19
 
13
- * No changes.
20
+ *Rafael Mendonça França*
21
+
22
+ * Return `false` when enqueuing a job is aborted.
14
23
 
24
+ *Rafael Mendonça França*
15
25
 
16
- ## Rails 5.2.4 (November 27, 2019) ##
26
+ * While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
27
+ `assert_enqueued_with`.
17
28
 
18
- * No changes.
29
+ *Dmitry Polushkin*
19
30
 
31
+ * `ActiveJob::TestCase#perform_enqueued_jobs` without a block removes performed jobs from the queue.
20
32
 
21
- ## Rails 5.2.3 (March 27, 2019) ##
33
+ That way the helper can be called multiple times and not perform a job invocation multiple times.
22
34
 
23
- * No changes.
35
+ ```ruby
36
+ def test_jobs
37
+ HelloJob.perform_later("rafael")
38
+ perform_enqueued_jobs # only runs with "rafael"
39
+ HelloJob.perform_later("david")
40
+ perform_enqueued_jobs # only runs with "david"
41
+ end
42
+ ```
24
43
 
44
+ *Étienne Barrié*
25
45
 
26
- ## Rails 5.2.2.1 (March 11, 2019) ##
46
+ * `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
27
47
 
28
- * No changes.
48
+ When calling `perform_enqueued_jobs` without a block, the adapter will
49
+ now perform jobs that are **already** in the queue. Jobs that will end up in
50
+ the queue afterwards won't be performed.
29
51
 
52
+ This change only affects `perform_enqueued_jobs` when no block is given.
30
53
 
31
- ## Rails 5.2.2 (December 04, 2018) ##
54
+ *Edouard Chin*
32
55
 
33
- * Make sure `assert_enqueued_with()` & `assert_performed_with()` work reliably with hash arguments.
56
+ * Add queue name support to Que adapter.
34
57
 
35
- *Sharang Dashputre*
58
+ *Brad Nauta*, *Wojciech Wnętrzak*
36
59
 
37
- * Restore `ActionController::Parameters` support to `ActiveJob::Arguments.serialize`.
60
+ * Don't run `after_enqueue` and `after_perform` callbacks if the callback chain is halted.
38
61
 
39
- *Bernie Chiu*
62
+ class MyJob < ApplicationJob
63
+ before_enqueue { throw(:abort) }
64
+ after_enqueue { # won't enter here anymore }
65
+ end
40
66
 
41
- * Restore `HashWithIndifferentAccess` support to `ActiveJob::Arguments.deserialize`.
67
+ `after_enqueue` and `after_perform` callbacks will no longer run if the callback chain is halted.
68
+ This behaviour is a breaking change and won't take effect until Rails 6.2.
69
+ To enable this behaviour in your app right now, you can add in your app's configuration file
70
+ `config.active_job.skip_after_callbacks_if_terminated = true`.
42
71
 
43
- *Gannon McGibbon*
72
+ *Edouard Chin*
44
73
 
45
- * Include deserialized arguments in job instances returned from
46
- `assert_enqueued_with` and `assert_performed_with`
74
+ * Fix enqueuing and performing incorrect logging message.
47
75
 
48
- *Alan Wu*
76
+ Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
49
77
 
50
- * Increment execution count before deserialize arguments.
78
+ ```ruby
79
+ class MyJob < ApplicationJob
80
+ before_enqueue { throw(:abort) }
81
+ end
51
82
 
52
- Currently, the execution count increments after deserializes arguments.
53
- Therefore, if an error occurs with deserialize, it retries indefinitely.
83
+ MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.
84
+ ```
54
85
 
55
- *Yuji Yaginuma*
86
+ A new message will be logged in case a job couldn't be enqueued, either because the callback chain was halted or
87
+ because an exception happened during enqueuing. (i.e. Redis is down when you try to enqueue your job)
56
88
 
89
+ *Edouard Chin*
57
90
 
58
- ## Rails 5.2.1.1 (November 27, 2018) ##
91
+ * Add an option to disable logging of the job arguments when enqueuing and executing the job.
59
92
 
60
- * Do not deserialize GlobalID objects that were not generated by Active Job.
93
+ class SensitiveJob < ApplicationJob
94
+ self.log_arguments = false
61
95
 
62
- Trusting any GlobaID object when deserializing jobs can allow attackers to access
63
- information that should not be accessible to them.
96
+ def perform(my_sensitive_argument)
97
+ end
98
+ end
64
99
 
65
- Fix CVE-2018-16476.
100
+ When dealing with sensitive arguments as password and tokens it is now possible to configure the job
101
+ to not put the sensitive argument in the logs.
66
102
 
67
103
  *Rafael Mendonça França*
68
104
 
105
+ * Changes in `queue_name_prefix` of a job no longer affects all other jobs.
69
106
 
70
- ## Rails 5.2.1 (August 07, 2018) ##
107
+ Fixes #37084.
71
108
 
72
- * Pass the error instance as the second parameter of block executed by `discard_on`.
109
+ *Lucas Mansur*
73
110
 
74
- Fixes #32853.
111
+ * Allow `Class` and `Module` instances to be serialized.
75
112
 
76
- *Yuji Yaginuma*
113
+ *Kevin Deisz*
77
114
 
78
- ## Rails 5.2.0 (April 09, 2018) ##
115
+ * Log potential matches in `assert_enqueued_with` and `assert_performed_with`.
79
116
 
80
- * Allow block to be passed to `ActiveJob::Base.discard_on` to allow custom handling of discard jobs.
117
+ *Gareth du Plooy*
81
118
 
82
- Example:
119
+ * Add `at` argument to the `perform_enqueued_jobs` test helper.
83
120
 
84
- class RemoteServiceJob < ActiveJob::Base
85
- discard_on(CustomAppException) do |job, exception|
86
- ExceptionNotifier.caught(exception)
87
- end
121
+ *John Crepezzi*, *Eileen Uchitelle*
88
122
 
89
- def perform(*args)
90
- # Might raise CustomAppException for something domain specific
91
- end
92
- end
123
+ * `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
124
+
125
+ *Vlado Cingel*
126
+
127
+ * Add jitter to `ActiveJob::Exceptions.retry_on`.
128
+
129
+ `ActiveJob::Exceptions.retry_on` now uses a random amount of jitter in order to
130
+ prevent the [thundering herd effect](https://en.wikipedia.org/wiki/Thundering_herd_problem). Defaults to
131
+ 15% (represented as 0.15) but overridable via the `:jitter` option when using `retry_on`.
132
+ Jitter is applied when an `Integer`, `ActiveSupport::Duration` or `:exponentially_longer`, is passed to the `wait` argument in `retry_on`.
93
133
 
94
- *Aidan Haran*
134
+ ```ruby
135
+ retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)
136
+ ```
95
137
 
96
- * Support redis-rb 4.0.
138
+ *Anthony Ross*
97
139
 
98
- *Jeremy Daer*
99
140
 
100
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md) for previous changes.
141
+ 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-2020 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
@@ -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/master/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
data/lib/active_job.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2014-2018 David Heinemeier Hansson
4
+ # Copyright (c) 2014-2020 David Heinemeier Hansson
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining
7
7
  # a copy of this software and associated documentation files (the
@@ -33,6 +33,7 @@ module ActiveJob
33
33
 
34
34
  autoload :Base
35
35
  autoload :QueueAdapters
36
+ autoload :Serializers
36
37
  autoload :ConfiguredJob
37
38
  autoload :TestCase
38
39
  autoload :TestHelper
@@ -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