activejob 5.2.8.1 → 6.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +69 -108
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +12 -6
  5. data/lib/active_job/arguments.rb +40 -28
  6. data/lib/active_job/base.rb +3 -1
  7. data/lib/active_job/callbacks.rb +4 -1
  8. data/lib/active_job/core.rb +33 -21
  9. data/lib/active_job/enqueuing.rb +26 -5
  10. data/lib/active_job/exceptions.rb +33 -17
  11. data/lib/active_job/execution.rb +1 -1
  12. data/lib/active_job/gem_version.rb +4 -4
  13. data/lib/active_job/logging.rb +39 -8
  14. data/lib/active_job/queue_adapter.rb +2 -0
  15. data/lib/active_job/queue_adapters/async_adapter.rb +1 -1
  16. data/lib/active_job/queue_adapters/backburner_adapter.rb +2 -2
  17. data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
  18. data/lib/active_job/queue_adapters/test_adapter.rb +22 -8
  19. data/lib/active_job/queue_adapters.rb +5 -7
  20. data/lib/active_job/queue_name.rb +1 -1
  21. data/lib/active_job/railtie.rb +16 -1
  22. data/lib/active_job/serializers/date_serializer.rb +21 -0
  23. data/lib/active_job/serializers/date_time_serializer.rb +21 -0
  24. data/lib/active_job/serializers/duration_serializer.rb +24 -0
  25. data/lib/active_job/serializers/object_serializer.rb +54 -0
  26. data/lib/active_job/serializers/symbol_serializer.rb +21 -0
  27. data/lib/active_job/serializers/time_serializer.rb +21 -0
  28. data/lib/active_job/serializers/time_with_zone_serializer.rb +21 -0
  29. data/lib/active_job/serializers.rb +63 -0
  30. data/lib/active_job/test_helper.rb +262 -56
  31. data/lib/active_job/timezones.rb +13 -0
  32. data/lib/active_job/translation.rb +1 -1
  33. data/lib/active_job.rb +2 -1
  34. data/lib/rails/generators/job/job_generator.rb +4 -0
  35. metadata +23 -15
  36. 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: 4efdf023b31288a45487abbafc8fc37207c470167a9f2d770a5d3364e4a7c399
4
+ data.tar.gz: e2476b972bf30c7bfb9cdce2ee2fb5018e2253d6b1bb28142dcbb169bf834c2d
5
5
  SHA512:
6
- metadata.gz: 86113704b57cd7ab3d3b4bcd411c104376cf9c453e285277f018e5d537492a4e9eaa41f417ef495f4b6f84be94867adad2d5306f01ff49bf5aeacd47583cbe40
7
- data.tar.gz: d971688295936bc31b1c2cc5c2bd611601598e9d9a3a9b9fa0c221d23bf61b88e76381c29398d20c751fec1333f4c37f78c58921e1d532af2b7f3a505dba7af4
6
+ metadata.gz: 2f5b5589be292b9df0693b61a38f8a1b5d8a8b88ecd4ec2eb22556f18fd8795fa7be9f447057626ed9f852bb543807a96eefa28989a27f16ee946a5e91550614
7
+ data.tar.gz: 694d741cfd413f0bae6165706b5924a6cb5ae7a6240d5fc6d09c3cc1b4020d1fc3006ae154b932a3734126530b3ff112c29f56839ca9b630ab7ed467dda3f38a
data/CHANGELOG.md CHANGED
@@ -1,160 +1,121 @@
1
- ## Rails 5.2.8.1 (July 12, 2022) ##
1
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
2
2
 
3
- * No changes.
3
+ * Return false instead of the job instance when `enqueue` is aborted.
4
4
 
5
+ This will be the behavior in Rails 6.1 but it can be controlled now with
6
+ `config.active_job.return_false_on_aborted_enqueue`.
5
7
 
6
- ## Rails 5.2.8 (May 09, 2022) ##
8
+ *Kir Shatrov*
7
9
 
8
- * No changes.
10
+ * Keep executions for each specific declaration
9
11
 
12
+ Each `retry_on` declaration has now its own specific executions counter. Before it was
13
+ shared between all executions of a job.
10
14
 
11
- ## Rails 5.2.7.1 (April 26, 2022) ##
15
+ *Alberto Almagro*
12
16
 
13
- * No changes.
17
+ * Allow all assertion helpers that have a `only` and `except` keyword to accept
18
+ Procs.
14
19
 
20
+ *Edouard Chin*
15
21
 
16
- ## Rails 5.2.7 (March 10, 2022) ##
22
+ * Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
17
23
 
18
- * No changes.
19
-
20
-
21
- ## Rails 5.2.6.3 (March 08, 2022) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 5.2.6.2 (February 11, 2022) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 5.2.6.1 (February 11, 2022) ##
32
-
33
- * No changes.
34
-
35
-
36
- ## Rails 5.2.6 (May 05, 2021) ##
37
-
38
- * No changes.
39
-
40
-
41
- ## Rails 5.2.5 (March 26, 2021) ##
42
-
43
- * No changes.
44
-
45
-
46
- ## Rails 5.2.4.6 (May 05, 2021) ##
47
-
48
- * No changes.
49
-
50
-
51
- ## Rails 5.2.4.5 (February 10, 2021) ##
52
-
53
- * No changes.
54
-
55
-
56
- ## Rails 5.2.4.4 (September 09, 2020) ##
57
-
58
- * No changes.
59
-
60
-
61
- ## Rails 5.2.4.3 (May 18, 2020) ##
24
+ *Gannon McGibbon*
62
25
 
63
- * No changes.
26
+ * Include deserialized arguments in job instances returned from
27
+ `assert_enqueued_with` and `assert_performed_with`
64
28
 
29
+ *Alan Wu*
65
30
 
66
- ## Rails 5.2.4.2 (March 19, 2020) ##
31
+ * Allow `assert_enqueued_with`/`assert_performed_with` methods to accept
32
+ a proc for the `args` argument. This is useful to check if only a subset of arguments
33
+ matches your expectations.
67
34
 
68
- * No changes.
35
+ *Edouard Chin*
69
36
 
37
+ * `ActionDispatch::IntegrationTest` includes `ActiveJob::TestHelper` module by default.
70
38
 
71
- ## Rails 5.2.4.1 (December 18, 2019) ##
39
+ *Ricardo Díaz*
72
40
 
73
- * No changes.
41
+ * Added `enqueue_retry.active_job`, `retry_stopped.active_job`, and `discard.active_job` hooks.
74
42
 
43
+ *steves*
75
44
 
76
- ## Rails 5.2.4 (November 27, 2019) ##
45
+ * Allow `assert_performed_with` to be called without a block.
77
46
 
78
- * No changes.
47
+ *bogdanvlviv*
79
48
 
49
+ * Execution of `assert_performed_jobs`, and `assert_no_performed_jobs`
50
+ without a block should respect passed `:except`, `:only`, and `:queue` options.
80
51
 
81
- ## Rails 5.2.3 (March 27, 2019) ##
52
+ *bogdanvlviv*
82
53
 
83
- * No changes.
54
+ * Allow `:queue` option to job assertions and helpers.
84
55
 
56
+ *bogdanvlviv*
85
57
 
86
- ## Rails 5.2.2.1 (March 11, 2019) ##
58
+ * Allow `perform_enqueued_jobs` to be called without a block.
87
59
 
88
- * No changes.
60
+ Performs all of the jobs that have been enqueued up to this point in the test.
89
61
 
62
+ *Kevin Deisz*
90
63
 
91
- ## Rails 5.2.2 (December 04, 2018) ##
64
+ * Move `enqueue`/`enqueue_at` notifications to an around callback.
92
65
 
93
- * Make sure `assert_enqueued_with()` & `assert_performed_with()` work reliably with hash arguments.
66
+ Improves timing accuracy over the old after callback by including
67
+ time spent writing to the adapter's IO implementation.
94
68
 
95
- *Sharang Dashputre*
69
+ *Zach Kemp*
96
70
 
97
- * Restore `ActionController::Parameters` support to `ActiveJob::Arguments.serialize`.
71
+ * Allow call `assert_enqueued_with` with no block.
98
72
 
99
- *Bernie Chiu*
73
+ Example:
74
+ ```
75
+ def test_assert_enqueued_with
76
+ MyJob.perform_later(1,2,3)
77
+ assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
100
78
 
101
- * Restore `HashWithIndifferentAccess` support to `ActiveJob::Arguments.deserialize`.
79
+ MyJob.set(wait_until: Date.tomorrow.noon).perform_later
80
+ assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
81
+ end
82
+ ```
102
83
 
103
- *Gannon McGibbon*
84
+ *bogdanvlviv*
104
85
 
105
- * Include deserialized arguments in job instances returned from
106
- `assert_enqueued_with` and `assert_performed_with`
86
+ * Allow passing multiple exceptions to `retry_on`, and `discard_on`.
107
87
 
108
- *Alan Wu*
88
+ *George Claghorn*
109
89
 
110
- * Increment execution count before deserialize arguments.
90
+ * Pass the error instance as the second parameter of block executed by `discard_on`.
111
91
 
112
- Currently, the execution count increments after deserializes arguments.
113
- Therefore, if an error occurs with deserialize, it retries indefinitely.
92
+ Fixes #32853.
114
93
 
115
94
  *Yuji Yaginuma*
116
95
 
96
+ * Remove support for Qu gem.
117
97
 
118
- ## Rails 5.2.1.1 (November 27, 2018) ##
98
+ Reasons are that the Qu gem wasn't compatible since Rails 5.1,
99
+ gem development was stopped in 2014 and maintainers have
100
+ confirmed its demise. See issue #32273
119
101
 
120
- * Do not deserialize GlobalID objects that were not generated by Active Job.
102
+ *Alberto Almagro*
121
103
 
122
- Trusting any GlobaID object when deserializing jobs can allow attackers to access
123
- information that should not be accessible to them.
104
+ * Add support for timezones to Active Job.
124
105
 
125
- Fix CVE-2018-16476.
106
+ Record what was the current timezone in effect when the job was
107
+ enqueued and then restore when the job is executed in same way
108
+ that the current locale is recorded and restored.
126
109
 
127
- *Rafael Mendonça França*
128
-
129
-
130
- ## Rails 5.2.1 (August 07, 2018) ##
131
-
132
- * Pass the error instance as the second parameter of block executed by `discard_on`.
133
-
134
- Fixes #32853.
135
-
136
- *Yuji Yaginuma*
137
-
138
- ## Rails 5.2.0 (April 09, 2018) ##
139
-
140
- * Allow block to be passed to `ActiveJob::Base.discard_on` to allow custom handling of discard jobs.
141
-
142
- Example:
110
+ *Andrew White*
143
111
 
144
- class RemoteServiceJob < ActiveJob::Base
145
- discard_on(CustomAppException) do |job, exception|
146
- ExceptionNotifier.caught(exception)
147
- end
112
+ * Rails 6 requires Ruby 2.5.0 or newer.
148
113
 
149
- def perform(*args)
150
- # Might raise CustomAppException for something domain specific
151
- end
152
- end
114
+ *Jeremy Daer*, *Kasper Timm Hansen*
153
115
 
154
- *Aidan Haran*
116
+ * Add support to define custom argument serializers.
155
117
 
156
- * Support redis-rb 4.0.
118
+ *Evgenii Pecherkin*, *Rafael Mendonça França*
157
119
 
158
- *Jeremy Daer*
159
120
 
160
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md) for previous changes.
121
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-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-2019 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
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
 
@@ -20,7 +20,7 @@ switch between them without having to rewrite your jobs.
20
20
 
21
21
  ## Usage
22
22
 
23
- To learn how to use your preferred queueing backend see its adapter
23
+ To learn how to use your preferred queuing backend see its adapter
24
24
  documentation at
25
25
  [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
26
26
 
@@ -39,7 +39,7 @@ end
39
39
  Enqueue a job like so:
40
40
 
41
41
  ```ruby
42
- MyJob.perform_later record # Enqueue a job to be performed as soon as the queueing system is free.
42
+ MyJob.perform_later record # Enqueue a job to be performed as soon as the queuing system is free.
43
43
  ```
44
44
 
45
45
  ```ruby
@@ -82,12 +82,18 @@ This works with any class that mixes in GlobalID::Identification, which
82
82
  by default has been mixed into Active Record classes.
83
83
 
84
84
 
85
- ## Supported queueing systems
85
+ ## Supported queuing systems
86
86
 
87
- Active Job has built-in adapters for multiple queueing backends (Sidekiq,
87
+ Active Job has built-in adapters for multiple queuing backends (Sidekiq,
88
88
  Resque, Delayed Job and others). To get an up-to-date list of the adapters
89
89
  see the API Documentation for [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
90
90
 
91
+ **Please note:** We are not accepting pull requests for new adapters. We
92
+ encourage library authors to provide an ActiveJob adapter as part of
93
+ their gem, or as a stand-alone gem. For discussion about this see the
94
+ following PRs: [23311](https://github.com/rails/rails/issues/23311#issuecomment-176275718),
95
+ [21406](https://github.com/rails/rails/pull/21406#issuecomment-138813484), and [#32285](https://github.com/rails/rails/pull/32285).
96
+
91
97
  ## Auxiliary gems
92
98
 
93
99
  * [activejob-stats](https://github.com/seuros/activejob-stats)
@@ -102,7 +108,7 @@ The latest version of Active Job can be installed with RubyGems:
102
108
 
103
109
  Source code can be downloaded as part of the Rails project on GitHub:
104
110
 
105
- * https://github.com/rails/rails/tree/5-2-stable/activejob
111
+ * https://github.com/rails/rails/tree/master/activejob
106
112
 
107
113
  ## License
108
114
 
@@ -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
@@ -44,17 +45,30 @@ module ActiveJob
44
45
  end
45
46
 
46
47
  private
48
+
49
+ # :nodoc:
50
+ PERMITTED_TYPES = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
51
+ # :nodoc:
52
+ GLOBALID_KEY = "_aj_globalid"
53
+ # :nodoc:
54
+ SYMBOL_KEYS_KEY = "_aj_symbol_keys"
47
55
  # :nodoc:
48
- GLOBALID_KEY = "_aj_globalid".freeze
56
+ WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access"
49
57
  # :nodoc:
50
- SYMBOL_KEYS_KEY = "_aj_symbol_keys".freeze
58
+ OBJECT_SERIALIZER_KEY = "_aj_serialized"
59
+
51
60
  # :nodoc:
52
- WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access".freeze
53
- private_constant :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
61
+ RESERVED_KEYS = [
62
+ GLOBALID_KEY, GLOBALID_KEY.to_sym,
63
+ SYMBOL_KEYS_KEY, SYMBOL_KEYS_KEY.to_sym,
64
+ OBJECT_SERIALIZER_KEY, OBJECT_SERIALIZER_KEY.to_sym,
65
+ WITH_INDIFFERENT_ACCESS_KEY, WITH_INDIFFERENT_ACCESS_KEY.to_sym,
66
+ ]
67
+ private_constant :PERMITTED_TYPES, :RESERVED_KEYS, :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
54
68
 
55
69
  def serialize_argument(argument)
56
70
  case argument
57
- when *TYPE_WHITELIST
71
+ when *PERMITTED_TYPES
58
72
  argument
59
73
  when GlobalID::Identification
60
74
  convert_to_global_id_hash(argument)
@@ -70,7 +84,7 @@ module ActiveJob
70
84
  when -> (arg) { arg.respond_to?(:permitted?) }
71
85
  serialize_indifferent_hash(argument.to_h)
72
86
  else
73
- raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
87
+ Serializers.serialize(argument)
74
88
  end
75
89
  end
76
90
 
@@ -78,13 +92,15 @@ module ActiveJob
78
92
  case argument
79
93
  when String
80
94
  argument
81
- when *TYPE_WHITELIST
95
+ when *PERMITTED_TYPES
82
96
  argument
83
97
  when Array
84
98
  argument.map { |arg| deserialize_argument(arg) }
85
99
  when Hash
86
100
  if serialized_global_id?(argument)
87
101
  deserialize_global_id argument
102
+ elsif custom_serialized?(argument)
103
+ Serializers.deserialize(argument)
88
104
  else
89
105
  deserialize_hash(argument)
90
106
  end
@@ -101,6 +117,10 @@ module ActiveJob
101
117
  GlobalID::Locator.locate hash[GLOBALID_KEY]
102
118
  end
103
119
 
120
+ def custom_serialized?(hash)
121
+ hash.key?(OBJECT_SERIALIZER_KEY)
122
+ end
123
+
104
124
  def serialize_hash(argument)
105
125
  argument.each_with_object({}) do |(key, value), hash|
106
126
  hash[serialize_hash_key(key)] = serialize_argument(value)
@@ -117,14 +137,6 @@ module ActiveJob
117
137
  result
118
138
  end
119
139
 
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
140
  def serialize_hash_key(key)
129
141
  case key
130
142
  when *RESERVED_KEYS
@@ -9,6 +9,7 @@ require "active_job/execution"
9
9
  require "active_job/callbacks"
10
10
  require "active_job/exceptions"
11
11
  require "active_job/logging"
12
+ require "active_job/timezones"
12
13
  require "active_job/translation"
13
14
 
14
15
  module ActiveJob #:nodoc:
@@ -39,7 +40,7 @@ module ActiveJob #:nodoc:
39
40
  # Records that are passed in are serialized/deserialized using Global
40
41
  # ID. More information can be found in Arguments.
41
42
  #
42
- # To enqueue a job to be performed as soon as the queueing system is free:
43
+ # To enqueue a job to be performed as soon as the queuing system is free:
43
44
  #
44
45
  # ProcessPhotoJob.perform_later(photo)
45
46
  #
@@ -67,6 +68,7 @@ module ActiveJob #:nodoc:
67
68
  include Callbacks
68
69
  include Exceptions
69
70
  include Logging
71
+ include Timezones
70
72
  include Translation
71
73
 
72
74
  ActiveSupport.run_load_hooks(:active_job, self)
@@ -29,6 +29,9 @@ module ActiveJob
29
29
  included do
30
30
  define_callbacks :perform
31
31
  define_callbacks :enqueue
32
+
33
+ class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false
34
+ self.return_false_on_aborted_enqueue = false
32
35
  end
33
36
 
34
37
  # These methods will be included into any Active Job object, adding
@@ -130,7 +133,7 @@ module ActiveJob
130
133
  set_callback(:enqueue, :after, *filters, &blk)
131
134
  end
132
135
 
133
- # Defines a callback that will get called around the enqueueing
136
+ # Defines a callback that will get called around the enqueuing
134
137
  # of the job.
135
138
  #
136
139
  # class VideoProcessJob < ActiveJob::Base
@@ -6,32 +6,39 @@ module ActiveJob
6
6
  module Core
7
7
  extend ActiveSupport::Concern
8
8
 
9
- included do
10
- # Job arguments
11
- attr_accessor :arguments
12
- attr_writer :serialized_arguments
9
+ # Job arguments
10
+ attr_accessor :arguments
11
+ attr_writer :serialized_arguments
13
12
 
14
- # Timestamp when the job should be performed
15
- attr_accessor :scheduled_at
13
+ # Timestamp when the job should be performed
14
+ attr_accessor :scheduled_at
16
15
 
17
- # Job Identifier
18
- attr_accessor :job_id
16
+ # Job Identifier
17
+ attr_accessor :job_id
19
18
 
20
- # Queue in which the job will reside.
21
- attr_writer :queue_name
19
+ # Queue in which the job will reside.
20
+ attr_writer :queue_name
22
21
 
23
- # Priority that the job will have (lower is more priority).
24
- attr_writer :priority
22
+ # Priority that the job will have (lower is more priority).
23
+ attr_writer :priority
25
24
 
26
- # ID optionally provided by adapter
27
- attr_accessor :provider_job_id
25
+ # ID optionally provided by adapter
26
+ attr_accessor :provider_job_id
28
27
 
29
- # Number of times this job has been executed (which increments on every retry, like after an exception).
30
- attr_accessor :executions
28
+ # Number of times this job has been executed (which increments on every retry, like after an exception).
29
+ attr_accessor :executions
31
30
 
32
- # I18n.locale to be used during the job.
33
- attr_accessor :locale
34
- end
31
+ # Hash that contains the number of times this job handled errors for each specific retry_on declaration.
32
+ # Keys are the string representation of the exceptions listed in the retry_on declaration,
33
+ # while its associated value holds the number of executions where the corresponding retry_on
34
+ # declaration handled one of its listed exceptions.
35
+ attr_accessor :exception_executions
36
+
37
+ # I18n.locale to be used during the job.
38
+ attr_accessor :locale
39
+
40
+ # Timezone to be used during the job.
41
+ attr_accessor :timezone
35
42
 
36
43
  # These methods will be included into any Active Job object, adding
37
44
  # helpers for de/serialization and creation of job instances.
@@ -74,10 +81,11 @@ module ActiveJob
74
81
  @queue_name = self.class.queue_name
75
82
  @priority = self.class.priority
76
83
  @executions = 0
84
+ @exception_executions = {}
77
85
  end
78
86
 
79
87
  # Returns a hash with the job data that can safely be passed to the
80
- # queueing adapter.
88
+ # queuing adapter.
81
89
  def serialize
82
90
  {
83
91
  "job_class" => self.class.name,
@@ -87,7 +95,9 @@ module ActiveJob
87
95
  "priority" => priority,
88
96
  "arguments" => serialize_arguments_if_needed(arguments),
89
97
  "executions" => executions,
90
- "locale" => I18n.locale.to_s
98
+ "exception_executions" => exception_executions,
99
+ "locale" => I18n.locale.to_s,
100
+ "timezone" => Time.zone.try(:name)
91
101
  }
92
102
  end
93
103
 
@@ -124,7 +134,9 @@ module ActiveJob
124
134
  self.priority = job_data["priority"]
125
135
  self.serialized_arguments = job_data["arguments"]
126
136
  self.executions = job_data["executions"]
137
+ self.exception_executions = job_data["exception_executions"]
127
138
  self.locale = job_data["locale"] || I18n.locale.to_s
139
+ self.timezone = job_data["timezone"] || Time.zone.try(:name)
128
140
  end
129
141
 
130
142
  private
@@ -9,10 +9,12 @@ module ActiveJob
9
9
 
10
10
  # Includes the +perform_later+ method for job initialization.
11
11
  module ClassMethods
12
- # Push a job onto the queue. The arguments must be legal JSON types
13
- # (+string+, +int+, +float+, +nil+, +true+, +false+, +hash+ or +array+) or
14
- # GlobalID::Identification instances. Arbitrary Ruby objects
15
- # are not supported.
12
+ # Push a job onto the queue. By default the arguments must be either String,
13
+ # Integer, Float, NilClass, TrueClass, FalseClass, BigDecimal, Symbol, Date,
14
+ # Time, DateTime, ActiveSupport::TimeWithZone, ActiveSupport::Duration,
15
+ # Hash, ActiveSupport::HashWithIndifferentAccess, Array or
16
+ # GlobalID::Identification instances, although this can be extended by adding
17
+ # custom serializers.
16
18
  #
17
19
  # Returns an instance of the job class queued with arguments available in
18
20
  # Job#arguments.
@@ -46,14 +48,33 @@ module ActiveJob
46
48
  self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
47
49
  self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
48
50
  self.priority = options[:priority].to_i if options[:priority]
51
+ successfully_enqueued = false
52
+
49
53
  run_callbacks :enqueue do
50
54
  if scheduled_at
51
55
  self.class.queue_adapter.enqueue_at self, scheduled_at
52
56
  else
53
57
  self.class.queue_adapter.enqueue self
54
58
  end
59
+
60
+ successfully_enqueued = true
61
+ end
62
+
63
+ if successfully_enqueued
64
+ self
65
+ else
66
+ if self.class.return_false_on_aborted_enqueue
67
+ false
68
+ else
69
+ ActiveSupport::Deprecation.warn(
70
+ "Rails 6.0 will return false when the enqueing is aborted. Make sure your code doesn't depend on it" \
71
+ " returning the instance of the job and set `config.active_job.return_false_on_aborted_enqueue = true`" \
72
+ " to remove the deprecations."
73
+ )
74
+
75
+ self
76
+ end
55
77
  end
56
- self
57
78
  end
58
79
  end
59
80
  end