activejob 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activejob might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +24 -221
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +1 -1
  5. data/lib/active_job.rb +5 -5
  6. data/lib/active_job/arguments.rb +7 -19
  7. data/lib/active_job/base.rb +11 -9
  8. data/lib/active_job/callbacks.rb +3 -3
  9. data/lib/active_job/configured_job.rb +1 -1
  10. data/lib/active_job/core.rb +14 -9
  11. data/lib/active_job/enqueuing.rb +7 -32
  12. data/lib/active_job/exceptions.rb +122 -0
  13. data/lib/active_job/execution.rb +5 -2
  14. data/lib/active_job/gem_version.rb +3 -3
  15. data/lib/active_job/logging.rb +56 -56
  16. data/lib/active_job/queue_adapter.rb +14 -26
  17. data/lib/active_job/queue_adapters.rb +2 -2
  18. data/lib/active_job/queue_adapters/async_adapter.rb +4 -4
  19. data/lib/active_job/queue_adapters/backburner_adapter.rb +1 -1
  20. data/lib/active_job/queue_adapters/delayed_job_adapter.rb +1 -1
  21. data/lib/active_job/queue_adapters/qu_adapter.rb +3 -3
  22. data/lib/active_job/queue_adapters/que_adapter.rb +1 -1
  23. data/lib/active_job/queue_adapters/queue_classic_adapter.rb +4 -4
  24. data/lib/active_job/queue_adapters/resque_adapter.rb +5 -5
  25. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +11 -11
  26. data/lib/active_job/queue_adapters/sneakers_adapter.rb +3 -3
  27. data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +3 -3
  28. data/lib/active_job/queue_adapters/test_adapter.rb +13 -17
  29. data/lib/active_job/queue_name.rb +2 -3
  30. data/lib/active_job/queue_priority.rb +1 -2
  31. data/lib/active_job/railtie.rb +4 -4
  32. data/lib/active_job/test_case.rb +1 -1
  33. data/lib/active_job/test_helper.rb +78 -39
  34. data/lib/active_job/version.rb +1 -1
  35. data/lib/rails/generators/job/job_generator.rb +12 -12
  36. data/lib/rails/generators/job/templates/application_job.rb +5 -0
  37. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ecdf4a56b98a2c195f395d7ce97d4156a7eed47df1f510b37ff57b2657dabef1
4
- data.tar.gz: dbde580495e6f009e966e3e19ba96612766f0f1b149e8cfdea47bab57c89834a
2
+ SHA1:
3
+ metadata.gz: f531ce0d6eaf7a50b34ce12d446306d52ee5c1c8
4
+ data.tar.gz: 75398a20122581b02e422c07798a7770d0481cdf
5
5
  SHA512:
6
- metadata.gz: 91dd626ddf7d659f4ddd0444b761198860195daad86132299e7734d668e0af7e1f92f471d73b7d398153fb38bc70be9796f6d400b659f63aa1a432a627434061
7
- data.tar.gz: 247bcb13011b91cb99fcf7e39119d9105bebba8cb6178b8d8d2a31cc012f7eecf6f5e94b10ead717ede24d0a160f7e2fd6f0c6049acf52d24c7742b873fd8150
6
+ metadata.gz: d70263baebf9c8476d0a45fe9e0eef753f35baaa221ebce00662971f46a1cc701fd51d9138194d445891954205ed6cfdf66573a6a107cf216ef7b0eaf2c28e70
7
+ data.tar.gz: f62463ae9aebd79e7933002dd9b2d786b74ca2dc28b94322fd3ea440b68c5c0d4ab0a59967a5f46d6932b869f4c62168878e5a9e48e49e7ea637597201276d85
@@ -1,76 +1,22 @@
1
- ## Rails 5.0.7.2 (March 11, 2019) ##
1
+ ## Rails 5.1.0.beta1 (February 23, 2017) ##
2
2
 
3
- * No changes.
3
+ * Correctly set test adapter when configure the queue adapter on a per job.
4
4
 
5
+ Fixes #26360.
5
6
 
6
- ## Rails 5.0.7.1 (November 27, 2018) ##
7
+ *Yuji Yaginuma*
7
8
 
8
- * Do not deserialize GlobalID objects that were not generated by Active Job.
9
+ * Push skipped jobs to `enqueued_jobs` when using `perform_enqueued_jobs` with a `only` filter in tests
9
10
 
10
- Trusting any GlobaID object when deserializing jobs can allow attackers to access
11
- information that should not be accessible to them.
11
+ *Alexander Pauly*
12
12
 
13
- Fix CVE-2018-16476.
13
+ * Removed deprecated support to passing the adapter class to `.queue_adapter`.
14
14
 
15
15
  *Rafael Mendonça França*
16
16
 
17
+ * Removed deprecated `#original_exception` in `ActiveJob::DeserializationError`.
17
18
 
18
- ## Rails 5.0.7 (March 29, 2018) ##
19
-
20
- * No changes.
21
-
22
-
23
- ## Rails 5.0.6 (September 07, 2017) ##
24
-
25
- * No changes.
26
-
27
-
28
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
29
-
30
- * No changes.
31
-
32
-
33
- ## Rails 5.0.5 (July 31, 2017) ##
34
-
35
- * No changes.
36
-
37
-
38
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
39
-
40
- * No changes.
41
-
42
-
43
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
44
-
45
- * No changes.
46
-
47
-
48
- ## Rails 5.0.4 (June 19, 2017) ##
49
-
50
- * No changes.
51
-
52
-
53
- ## Rails 5.0.3 (May 12, 2017) ##
54
-
55
- * No changes.
56
-
57
-
58
- ## Rails 5.0.2 (March 01, 2017) ##
59
-
60
- * No changes.
61
-
62
-
63
- ## Rails 5.0.1 (December 21, 2016) ##
64
-
65
- * No changes.
66
-
67
-
68
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
69
-
70
- * No changes.
71
-
72
-
73
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
19
+ *Rafael Mendonça França*
74
20
 
75
21
  * Added instance variable `@queue` to JobWrapper.
76
22
 
@@ -79,172 +25,29 @@
79
25
 
80
26
  *mu29*
81
27
 
82
-
83
- ## Rails 5.0.0 (June 30, 2016) ##
84
-
85
- * Enable class reloading prior to job dispatch, and ensure Active Record
86
- connections are returned to the pool when jobs are run in separate threads.
87
-
88
- *Matthew Draper*
89
-
90
- * Tune the async adapter for low-footprint dev/test usage. Use a single
91
- thread pool for all queues and limit to 0 to #CPU total threads, down from
92
- 2 to 10*#CPU per queue.
93
-
94
- *Jeremy Daer*
95
-
96
- * Change the default adapter from inline to async. It's a better default as tests will then not mistakenly
97
- come to rely on behavior happening synchronously. This is especially important with things like jobs kicked off
98
- in Active Record lifecycle callbacks.
28
+ * Yield the job instance so you have access to things like `job.arguments` on the custom logic after retries fail.
99
29
 
100
30
  *DHH*
101
31
 
102
- * Fixed serializing `:at` option for `assert_enqueued_with`
103
- and `assert_performed_with`.
104
-
105
- *Wojciech Wnętrzak*
106
-
107
- * Support passing array to `assert_enqueued_jobs` in `:only` option.
108
-
109
- *Wojciech Wnętrzak*
110
-
111
- * Add job priorities to Active Job.
112
-
113
- *wvengen*
114
-
115
- * Implement a simple `AsyncJob` processor and associated `AsyncAdapter` that
116
- queue jobs to a `concurrent-ruby` thread pool.
117
-
118
- *Jerry D'Antonio*
119
-
120
- * Implement `provider_job_id` for `queue_classic` adapter. This requires the
121
- latest, currently unreleased, version of queue_classic.
32
+ * Added declarative exception handling via `ActiveJob::Base.retry_on` and `ActiveJob::Base.discard_on`.
122
33
 
123
- *Yves Senn*
34
+ Examples:
124
35
 
125
- * `assert_enqueued_with` and `assert_performed_with` now returns the matched
126
- job instance for further assertions.
36
+ class RemoteServiceJob < ActiveJob::Base
37
+ retry_on CustomAppException # defaults to 3s wait, 5 attempts
38
+ retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 }
39
+ retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
40
+ retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10
41
+ discard_on ActiveJob::DeserializationError
127
42
 
128
- *Jean Boussier*
129
-
130
- * Include `I18n.locale` into job serialization/deserialization and use it around
131
- `perform`.
132
-
133
- Fixes #20799.
134
-
135
- *Johannes Opper*
136
-
137
- * Allow `DelayedJob`, `Sidekiq`, `qu`, and `que` to report the job id back to
138
- `ActiveJob::Base` as `provider_job_id`.
139
-
140
- Fixes #18821.
141
-
142
- *Kevin Deisz*, *Jeroen van Baarsen*
143
-
144
- * `assert_enqueued_jobs` and `assert_performed_jobs` in block form use the
145
- given number as expected value. This makes the error message much easier to
146
- understand.
147
-
148
- *y-yagi*
149
-
150
- * A generated job now inherits from `app/jobs/application_job.rb` by default.
151
-
152
- *Jeroen van Baarsen*
153
-
154
- * Add ability to configure the queue adapter on a per job basis.
155
-
156
- Now different jobs can have different queue adapters without conflicting with
157
- each other.
158
-
159
- Example:
160
-
161
- class EmailJob < ActiveJob::Base
162
- self.queue_adapter = :sidekiq
163
- end
164
-
165
- class ImageProcessingJob < ActiveJob::Base
166
- self.queue_adapter = :delayed_job
167
- end
168
-
169
- *tamird*
170
-
171
- * Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on
172
- type.
173
-
174
- This allows specific jobs to be tested, while preventing others from
175
- being performed unnecessarily.
176
-
177
- Example:
178
-
179
- def test_hello_job
180
- assert_performed_jobs 1, only: HelloJob do
181
- HelloJob.perform_later('jeremy')
182
- LoggingJob.perform_later
183
- end
184
- end
185
-
186
- An array may also be specified, to support testing multiple jobs.
187
-
188
- Example:
189
-
190
- def test_hello_and_logging_jobs
191
- assert_nothing_raised do
192
- assert_performed_jobs 2, only: [HelloJob, LoggingJob] do
193
- HelloJob.perform_later('jeremy')
194
- LoggingJob.perform_later('stewie')
195
- RescueJob.perform_later('david')
196
- end
197
- end
198
- end
199
-
200
- Fixes #18802.
201
-
202
- *Michael Ryan*
203
-
204
- * Allow keyword arguments to be used with Active Job.
205
-
206
- Fixes #18741.
207
-
208
- *Sean Griffin*
209
-
210
- * Add `:only` option to `assert_enqueued_jobs`, to check the number of times
211
- a specific kind of job is enqueued.
212
-
213
- Example:
214
-
215
- def test_logging_job
216
- assert_enqueued_jobs 1, only: LoggingJob do
217
- LoggingJob.perform_later
218
- HelloJob.perform_later('jeremy')
43
+ def perform(*args)
44
+ # Might raise CustomAppException or AnotherCustomAppException for something domain specific
45
+ # Might raise ActiveRecord::Deadlocked when a local db deadlock is detected
46
+ # Might raise Net::OpenTimeout when the remote service is down
219
47
  end
220
48
  end
221
49
 
222
- *George Claghorn*
223
-
224
- * `ActiveJob::Base.deserialize` delegates to the job class.
225
-
226
- Since `ActiveJob::Base#deserialize` can be overridden by subclasses (like
227
- `ActiveJob::Base#serialize`) this allows jobs to attach arbitrary metadata
228
- when they get serialized and read it back when they get performed.
229
-
230
- Example:
231
-
232
- class DeliverWebhookJob < ActiveJob::Base
233
- def serialize
234
- super.merge('attempt_number' => (@attempt_number || 0) + 1)
235
- end
236
-
237
- def deserialize(job_data)
238
- super
239
- @attempt_number = job_data['attempt_number']
240
- end
241
-
242
- rescue_from(TimeoutError) do |exception|
243
- raise exception if @attempt_number > 5
244
- retry_job(wait: 10)
245
- end
246
- end
50
+ *DHH*
247
51
 
248
- *Isaac Seymour*
249
52
 
250
- Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activejob/CHANGELOG.md) for previous changes.
53
+ Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activejob/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2016 David Heinemeier Hansson
1
+ Copyright (c) 2014-2017 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
@@ -102,7 +102,7 @@ The latest version of Active Job can be installed with RubyGems:
102
102
 
103
103
  Source code can be downloaded as part of the Rails project on GitHub
104
104
 
105
- * https://github.com/rails/rails/tree/5-0-stable/activejob
105
+ * https://github.com/rails/rails/tree/master/activejob
106
106
 
107
107
  ## License
108
108
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2014-2016 David Heinemeier Hansson
2
+ # Copyright (c) 2014-2017 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,10 +21,10 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'active_support'
25
- require 'active_support/rails'
26
- require 'active_job/version'
27
- require 'global_id'
24
+ require "active_support"
25
+ require "active_support/rails"
26
+ require "active_job/version"
27
+ require "global_id"
28
28
 
29
29
  module ActiveJob
30
30
  extend ActiveSupport::Autoload
@@ -1,26 +1,14 @@
1
- require 'active_support/core_ext/hash'
1
+ require "active_support/core_ext/hash"
2
2
 
3
3
  module ActiveJob
4
4
  # Raised when an exception is raised during job arguments deserialization.
5
5
  #
6
6
  # Wraps the original exception raised as +cause+.
7
7
  class DeserializationError < StandardError
8
- def initialize(e = nil) #:nodoc:
9
- if e
10
- ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
11
- "Exceptions will automatically capture the original exception.", caller)
12
- end
13
-
8
+ def initialize #:nodoc:
14
9
  super("Error while trying to deserialize arguments: #{$!.message}")
15
10
  set_backtrace $!.backtrace
16
11
  end
17
-
18
- # The original exception that was raised during deserialization of job
19
- # arguments.
20
- def original_exception
21
- ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
22
- cause
23
- end
24
12
  end
25
13
 
26
14
  # Raised when an unsupported argument type is set as a job argument. We
@@ -55,11 +43,11 @@ module ActiveJob
55
43
 
56
44
  private
57
45
  # :nodoc:
58
- GLOBALID_KEY = '_aj_globalid'.freeze
46
+ GLOBALID_KEY = "_aj_globalid".freeze
59
47
  # :nodoc:
60
- SYMBOL_KEYS_KEY = '_aj_symbol_keys'.freeze
48
+ SYMBOL_KEYS_KEY = "_aj_symbol_keys".freeze
61
49
  # :nodoc:
62
- WITH_INDIFFERENT_ACCESS_KEY = '_aj_hash_with_indifferent_access'.freeze
50
+ WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access".freeze
63
51
  private_constant :GLOBALID_KEY, :SYMBOL_KEYS_KEY, :WITH_INDIFFERENT_ACCESS_KEY
64
52
 
65
53
  def serialize_argument(argument)
@@ -87,7 +75,7 @@ module ActiveJob
87
75
  def deserialize_argument(argument)
88
76
  case argument
89
77
  when String
90
- argument
78
+ GlobalID::Locator.locate(argument) || argument
91
79
  when *TYPE_WHITELIST
92
80
  argument
93
81
  when Array
@@ -104,7 +92,7 @@ module ActiveJob
104
92
  end
105
93
 
106
94
  def serialized_global_id?(hash)
107
- hash.size == 1 and hash.include?(GLOBALID_KEY)
95
+ hash.size == 1 && hash.include?(GLOBALID_KEY)
108
96
  end
109
97
 
110
98
  def deserialize_global_id(hash)
@@ -1,12 +1,13 @@
1
- require 'active_job/core'
2
- require 'active_job/queue_adapter'
3
- require 'active_job/queue_name'
4
- require 'active_job/queue_priority'
5
- require 'active_job/enqueuing'
6
- require 'active_job/execution'
7
- require 'active_job/callbacks'
8
- require 'active_job/logging'
9
- require 'active_job/translation'
1
+ require "active_job/core"
2
+ require "active_job/queue_adapter"
3
+ require "active_job/queue_name"
4
+ require "active_job/queue_priority"
5
+ require "active_job/enqueuing"
6
+ require "active_job/execution"
7
+ require "active_job/callbacks"
8
+ require "active_job/exceptions"
9
+ require "active_job/logging"
10
+ require "active_job/translation"
10
11
 
11
12
  module ActiveJob #:nodoc:
12
13
  # = Active Job
@@ -62,6 +63,7 @@ module ActiveJob #:nodoc:
62
63
  include Enqueuing
63
64
  include Execution
64
65
  include Callbacks
66
+ include Exceptions
65
67
  include Logging
66
68
  include Translation
67
69
 
@@ -1,4 +1,4 @@
1
- require 'active_support/callbacks'
1
+ require "active_support/callbacks"
2
2
 
3
3
  module ActiveJob
4
4
  # = Active Job Callbacks
@@ -126,8 +126,8 @@ module ActiveJob
126
126
  set_callback(:enqueue, :after, *filters, &blk)
127
127
  end
128
128
 
129
- # Defines a callback that will get called before and after the
130
- # job is enqueued.
129
+ # Defines a callback that will get called around the enqueueing
130
+ # of the job.
131
131
  #
132
132
  # class VideoProcessJob < ActiveJob::Base
133
133
  # queue_as :default
@@ -1,6 +1,6 @@
1
1
  module ActiveJob
2
2
  class ConfiguredJob #:nodoc:
3
- def initialize(job_class, options={})
3
+ def initialize(job_class, options = {})
4
4
  @options = options
5
5
  @job_class = job_class
6
6
  end
@@ -24,6 +24,9 @@ module ActiveJob
24
24
  # ID optionally provided by adapter
25
25
  attr_accessor :provider_job_id
26
26
 
27
+ # Number of times this job has been executed (which increments on every retry, like after an exception).
28
+ attr_accessor :executions
29
+
27
30
  # I18n.locale to be used during the job.
28
31
  attr_accessor :locale
29
32
  end
@@ -33,7 +36,7 @@ module ActiveJob
33
36
  module ClassMethods
34
37
  # Creates a new job instance from a hash created with +serialize+
35
38
  def deserialize(job_data)
36
- job = job_data['job_class'].constantize.new
39
+ job = job_data["job_class"].constantize.new
37
40
  job.deserialize(job_data)
38
41
  job
39
42
  end
@@ -56,7 +59,7 @@ module ActiveJob
56
59
  # VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last)
57
60
  # VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last)
58
61
  # VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last)
59
- def set(options={})
62
+ def set(options = {})
60
63
  ConfiguredJob.new(self, options)
61
64
  end
62
65
  end
@@ -68,6 +71,7 @@ module ActiveJob
68
71
  @job_id = SecureRandom.uuid
69
72
  @queue_name = self.class.queue_name
70
73
  @priority = self.class.priority
74
+ @executions = 0
71
75
  end
72
76
 
73
77
  # Returns a hash with the job data that can safely be passed to the
@@ -76,10 +80,10 @@ module ActiveJob
76
80
  {
77
81
  "job_class" => self.class.name,
78
82
  "job_id" => job_id,
79
- "provider_job_id" => provider_job_id,
80
83
  "queue_name" => queue_name,
81
84
  "priority" => priority,
82
85
  "arguments" => serialize_arguments(arguments),
86
+ "executions" => executions,
83
87
  "locale" => I18n.locale.to_s
84
88
  }
85
89
  end
@@ -105,12 +109,13 @@ module ActiveJob
105
109
  # end
106
110
  # end
107
111
  def deserialize(job_data)
108
- self.job_id = job_data['job_id']
109
- self.provider_job_id = job_data['provider_job_id']
110
- self.queue_name = job_data['queue_name']
111
- self.priority = job_data['priority']
112
- self.serialized_arguments = job_data['arguments']
113
- self.locale = job_data['locale'] || I18n.locale.to_s
112
+ self.job_id = job_data["job_id"]
113
+ self.provider_job_id = job_data["provider_job_id"]
114
+ self.queue_name = job_data["queue_name"]
115
+ self.priority = job_data["priority"]
116
+ self.serialized_arguments = job_data["arguments"]
117
+ self.executions = job_data["executions"]
118
+ self.locale = job_data["locale"] || I18n.locale.to_s
114
119
  end
115
120
 
116
121
  private