activejob 6.0.3.1 → 6.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c6163a34634ae189a8ec46a32cd8e2f292e3c565d945aca0b461afee089ec68
4
- data.tar.gz: a34908b6ccff83ed35b5c83274105713011b9d22f68d22a9b08648a3e61a27f9
3
+ metadata.gz: 440134b603c43896fefc8ab03b787679e37e8862f896a7ac55e45949b765f0a4
4
+ data.tar.gz: c98cec1ff12d0b6e56200bd99e25480eaf171aea2e0f252e68b5cd442f6782cb
5
5
  SHA512:
6
- metadata.gz: 25112718e0d255f3ba2cbe779925a083dffed238c7d5ceb2d823b9664364ca807e394a1856212afca0f7801117300b76b53b87e85fe66d0a43b64d6d4da2d240
7
- data.tar.gz: 1d44968c18701431c825b54d830290c5bf0c119e50381e0a9e02f0f983cc7322a01c563944158aa66868d2f9dcc821c65767a7ff42d303f9a628fc3817127405
6
+ metadata.gz: 173c876fb4b08fdcb3ef3acb7e32e9d8b793044f80d0cd8490204772a2e730a58e7cf12b3b3392b0a808c79811bc2e984c114eacb86ee689ce8914b067249289
7
+ data.tar.gz: 219b5cf6e8acf7ecb429553ce27e157f6ff4efc8aee38cf605119b7cb997a84cfd333015400707220423e41950ce698adf8769ace6da5649cc64ce04a07247a8
@@ -1,198 +1,135 @@
1
- ## Rails 6.0.3.1 (May 18, 2020) ##
1
+ ## Rails 6.1.0.rc2 (December 01, 2020) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 6.0.3 (May 06, 2020) ##
6
+ ## Rails 6.1.0.rc1 (November 02, 2020) ##
7
7
 
8
- * While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
9
- `assert_enqueued_with`.
10
-
11
- *Dmitry Polushkin*
12
-
13
- * Add queue name support to Que adapter
14
-
15
- *Brad Nauta*, *Wojciech Wnętrzak*
16
-
17
-
18
- ## Rails 6.0.2.2 (March 19, 2020) ##
19
-
20
- * No changes.
21
-
22
-
23
- ## Rails 6.0.2.1 (December 18, 2019) ##
24
-
25
- * No changes.
26
-
27
-
28
- ## Rails 6.0.2 (December 13, 2019) ##
8
+ * Recover nano precision when serializing `Time`, `TimeWithZone` and `DateTime` objects.
29
9
 
30
- * Allow Sidekiq access to the underlying job class.
31
-
32
- By having access to the Active Job class, Sidekiq can get access to any `sidekiq_options` which
33
- have been set on that Active Job type and serialize those options into Redis.
34
-
35
- https://github.com/mperham/sidekiq/blob/master/Changes.md#60
36
-
37
- *Mike Perham*
38
-
39
-
40
- ## Rails 6.0.1 (November 5, 2019) ##
41
-
42
- * No changes.
43
-
44
-
45
- ## Rails 6.0.0 (August 16, 2019) ##
46
-
47
- * `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
48
-
49
- *Vlado Cingel*
50
-
51
-
52
- ## Rails 6.0.0.rc2 (July 22, 2019) ##
53
-
54
- * No changes.
10
+ *Alan Tan*
55
11
 
12
+ * Deprecate `config.active_job.return_false_on_aborted_enqueue`.
56
13
 
57
- ## Rails 6.0.0.rc1 (April 24, 2019) ##
14
+ *Rafael Mendonça França*
58
15
 
59
- * Use individual execution counters when calculating retry delay.
16
+ * Return `false` when enqueuing a job is aborted.
60
17
 
61
- *Patrik Bóna*
18
+ *Rafael Mendonça França*
62
19
 
63
- * Make job argument assertions with `Time`, `ActiveSupport::TimeWithZone`, and `DateTime` work by dropping microseconds. Microsecond precision is lost during serialization.
64
-
65
- *Gannon McGibbon*
20
+ * While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
21
+ `assert_enqueued_with`.
66
22
 
23
+ *Dmitry Polushkin*
67
24
 
68
- ## Rails 6.0.0.beta3 (March 11, 2019) ##
25
+ * `ActiveJob::TestCase#perform_enqueued_jobs` without a block removes performed jobs from the queue.
69
26
 
70
- * No changes.
27
+ That way the helper can be called multiple times and not perform a job invocation multiple times.
71
28
 
29
+ ```ruby
30
+ def test_jobs
31
+ HelloJob.perform_later("rafael")
32
+ perform_enqueued_jobs # only runs with "rafael"
33
+ HelloJob.perform_later("david")
34
+ perform_enqueued_jobs # only runs with "david"
35
+ end
36
+ ```
72
37
 
73
- ## Rails 6.0.0.beta2 (February 25, 2019) ##
74
-
75
- * No changes.
38
+ *Étienne Barrié*
76
39
 
40
+ * `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
77
41
 
78
- ## Rails 6.0.0.beta1 (January 18, 2019) ##
42
+ When calling `perform_enqueued_jobs` without a block, the adapter will
43
+ now perform jobs that are **already** in the queue. Jobs that will end up in
44
+ the queue afterwards won't be performed.
79
45
 
80
- * Return false instead of the job instance when `enqueue` is aborted.
46
+ This change only affects `perform_enqueued_jobs` when no block is given.
81
47
 
82
- This will be the behavior in Rails 6.1 but it can be controlled now with
83
- `config.active_job.return_false_on_aborted_enqueue`.
48
+ *Edouard Chin*
84
49
 
85
- *Kir Shatrov*
50
+ * Add queue name support to Que adapter.
86
51
 
87
- * Keep executions for each specific declaration
52
+ *Brad Nauta*, *Wojciech Wnętrzak*
88
53
 
89
- Each `retry_on` declaration has now its own specific executions counter. Before it was
90
- shared between all executions of a job.
54
+ * Don't run `after_enqueue` and `after_perform` callbacks if the callback chain is halted.
91
55
 
92
- *Alberto Almagro*
56
+ class MyJob < ApplicationJob
57
+ before_enqueue { throw(:abort) }
58
+ after_enqueue { # won't enter here anymore }
59
+ end
93
60
 
94
- * Allow all assertion helpers that have a `only` and `except` keyword to accept
95
- Procs.
61
+ `after_enqueue` and `after_perform` callbacks will no longer run if the callback chain is halted.
62
+ This behaviour is a breaking change and won't take effect until Rails 6.2.
63
+ To enable this behaviour in your app right now, you can add in your app's configuration file
64
+ `config.active_job.skip_after_callbacks_if_terminated = true`.
96
65
 
97
66
  *Edouard Chin*
98
67
 
99
- * Restore `HashWithIndifferentAccess` support to `ActiveJob::Arguments.deserialize`.
68
+ * Fix enqueuing and performing incorrect logging message.
100
69
 
101
- *Gannon McGibbon*
70
+ Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
102
71
 
103
- * Include deserialized arguments in job instances returned from
104
- `assert_enqueued_with` and `assert_performed_with`
72
+ ```ruby
73
+ class MyJob < ApplicationJob
74
+ before_enqueue { throw(:abort) }
75
+ end
105
76
 
106
- *Alan Wu*
77
+ MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.
78
+ ```
107
79
 
108
- * Allow `assert_enqueued_with`/`assert_performed_with` methods to accept
109
- a proc for the `args` argument. This is useful to check if only a subset of arguments
110
- matches your expectations.
80
+ A new message will be logged in case a job couldn't be enqueued, either because the callback chain was halted or
81
+ because an exception happened during enqueuing. (i.e. Redis is down when you try to enqueue your job)
111
82
 
112
83
  *Edouard Chin*
113
84
 
114
- * `ActionDispatch::IntegrationTest` includes `ActiveJob::TestHelper` module by default.
115
-
116
- *Ricardo Díaz*
85
+ * Add an option to disable logging of the job arguments when enqueuing and executing the job.
117
86
 
118
- * Added `enqueue_retry.active_job`, `retry_stopped.active_job`, and `discard.active_job` hooks.
87
+ class SensitiveJob < ApplicationJob
88
+ self.log_arguments = false
119
89
 
120
- *steves*
90
+ def perform(my_sensitive_argument)
91
+ end
92
+ end
121
93
 
122
- * Allow `assert_performed_with` to be called without a block.
94
+ When dealing with sensitive arguments as password and tokens it is now possible to configure the job
95
+ to not put the sensitive argument in the logs.
123
96
 
124
- *bogdanvlviv*
97
+ *Rafael Mendonça França*
125
98
 
126
- * Execution of `assert_performed_jobs`, and `assert_no_performed_jobs`
127
- without a block should respect passed `:except`, `:only`, and `:queue` options.
99
+ * Changes in `queue_name_prefix` of a job no longer affects all other jobs.
128
100
 
129
- *bogdanvlviv*
101
+ Fixes #37084.
130
102
 
131
- * Allow `:queue` option to job assertions and helpers.
103
+ *Lucas Mansur*
132
104
 
133
- *bogdanvlviv*
134
-
135
- * Allow `perform_enqueued_jobs` to be called without a block.
136
-
137
- Performs all of the jobs that have been enqueued up to this point in the test.
105
+ * Allow `Class` and `Module` instances to be serialized.
138
106
 
139
107
  *Kevin Deisz*
140
108
 
141
- * Move `enqueue`/`enqueue_at` notifications to an around callback.
109
+ * Log potential matches in `assert_enqueued_with` and `assert_performed_with`.
142
110
 
143
- Improves timing accuracy over the old after callback by including
144
- time spent writing to the adapter's IO implementation.
111
+ *Gareth du Plooy*
145
112
 
146
- *Zach Kemp*
113
+ * Add `at` argument to the `perform_enqueued_jobs` test helper.
147
114
 
148
- * Allow call `assert_enqueued_with` with no block.
149
-
150
- Example:
151
- ```
152
- def test_assert_enqueued_with
153
- MyJob.perform_later(1,2,3)
154
- assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
115
+ *John Crepezzi*, *Eileen Uchitelle*
155
116
 
156
- MyJob.set(wait_until: Date.tomorrow.noon).perform_later
157
- assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
158
- end
159
- ```
160
-
161
- *bogdanvlviv*
162
-
163
- * Allow passing multiple exceptions to `retry_on`, and `discard_on`.
164
-
165
- *George Claghorn*
166
-
167
- * Pass the error instance as the second parameter of block executed by `discard_on`.
168
-
169
- Fixes #32853.
170
-
171
- *Yuji Yaginuma*
172
-
173
- * Remove support for Qu gem.
174
-
175
- Reasons are that the Qu gem wasn't compatible since Rails 5.1,
176
- gem development was stopped in 2014 and maintainers have
177
- confirmed its demise. See issue #32273
178
-
179
- *Alberto Almagro*
180
-
181
- * Add support for timezones to Active Job.
182
-
183
- Record what was the current timezone in effect when the job was
184
- enqueued and then restore when the job is executed in same way
185
- that the current locale is recorded and restored.
117
+ * `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
186
118
 
187
- *Andrew White*
119
+ *Vlado Cingel*
188
120
 
189
- * Rails 6 requires Ruby 2.5.0 or newer.
121
+ * Add jitter to `ActiveJob::Exceptions.retry_on`.
190
122
 
191
- *Jeremy Daer*, *Kasper Timm Hansen*
123
+ `ActiveJob::Exceptions.retry_on` now uses a random amount of jitter in order to
124
+ prevent the [thundering herd effect](https://en.wikipedia.org/wiki/Thundering_herd_problem). Defaults to
125
+ 15% (represented as 0.15) but overridable via the `:jitter` option when using `retry_on`.
126
+ Jitter is applied when an `Integer`, `ActiveSupport::Duration` or `:exponentially_longer`, is passed to the `wait` argument in `retry_on`.
192
127
 
193
- * Add support to define custom argument serializers.
128
+ ```ruby
129
+ retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)
130
+ ```
194
131
 
195
- *Evgenii Pecherkin*, *Rafael Mendonça França*
132
+ *Anthony Ross*
196
133
 
197
134
 
198
- Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activejob/CHANGELOG.md) for previous changes.
135
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activejob/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 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
@@ -95,9 +95,6 @@ their gem, or as a stand-alone gem. For discussion about this see the
95
95
  following PRs: [23311](https://github.com/rails/rails/issues/23311#issuecomment-176275718),
96
96
  [21406](https://github.com/rails/rails/pull/21406#issuecomment-138813484), and [#32285](https://github.com/rails/rails/pull/32285).
97
97
 
98
- ## Auxiliary gems
99
-
100
- * [activejob-stats](https://github.com/seuros/activejob-stats)
101
98
 
102
99
  ## Download and installation
103
100
 
@@ -111,6 +108,7 @@ Source code can be downloaded as part of the Rails project on GitHub:
111
108
 
112
109
  * https://github.com/rails/rails/tree/master/activejob
113
110
 
111
+
114
112
  ## License
115
113
 
116
114
  Active Job is released under the MIT license:
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2014-2019 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
@@ -8,7 +8,9 @@ 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"
12
14
  require "active_job/timezones"
13
15
  require "active_job/translation"
14
16
 
@@ -68,6 +70,7 @@ module ActiveJob #:nodoc:
68
70
  include Callbacks
69
71
  include Exceptions
70
72
  include Logging
73
+ include Instrumentation
71
74
  include Timezones
72
75
  include Translation
73
76
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/callbacks"
4
+ require "active_support/core_ext/object/with_options"
5
+ require "active_support/core_ext/module/attribute_accessors"
4
6
 
5
7
  module ActiveJob
6
8
  # = Active Job Callbacks
@@ -27,16 +29,25 @@ module ActiveJob
27
29
  end
28
30
 
29
31
  included do
30
- define_callbacks :perform
31
- define_callbacks :enqueue
32
+ class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false, default: false
33
+ singleton_class.deprecate :return_false_on_aborted_enqueue, :return_false_on_aborted_enqueue=
34
+ cattr_accessor :skip_after_callbacks_if_terminated, instance_accessor: false, default: false
32
35
 
33
- class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false
34
- self.return_false_on_aborted_enqueue = false
36
+ with_options(skip_after_callbacks_if_terminated: skip_after_callbacks_if_terminated) do
37
+ define_callbacks :perform
38
+ define_callbacks :enqueue
39
+ end
35
40
  end
36
41
 
37
42
  # These methods will be included into any Active Job object, adding
38
43
  # callbacks for +perform+ and +enqueue+ methods.
39
44
  module ClassMethods
45
+ def inherited(klass)
46
+ klass.get_callbacks(:enqueue).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated
47
+ klass.get_callbacks(:perform).config[:skip_after_callbacks_if_terminated] = skip_after_callbacks_if_terminated
48
+ super
49
+ end
50
+
40
51
  # Defines a callback that will get called right before the
41
52
  # job's perform method is executed.
42
53
  #
@@ -91,6 +102,19 @@ module ActiveJob
91
102
  # end
92
103
  # end
93
104
  #
105
+ # You can access the return value of the job only if the execution wasn't halted.
106
+ #
107
+ # class VideoProcessJob < ActiveJob::Base
108
+ # around_perform do |job, block|
109
+ # value = block.call
110
+ # puts value # => "Hello World!"
111
+ # end
112
+ #
113
+ # def perform
114
+ # "Hello World!"
115
+ # end
116
+ # end
117
+ #
94
118
  def around_perform(*filters, &blk)
95
119
  set_callback(:perform, :around, *filters, &blk)
96
120
  end
@@ -154,5 +178,21 @@ module ActiveJob
154
178
  set_callback(:enqueue, :around, *filters, &blk)
155
179
  end
156
180
  end
181
+
182
+ private
183
+ def halted_callback_hook(_filter, name) # :nodoc:
184
+ return super unless %i(enqueue perform).include?(name.to_sym)
185
+ callbacks = public_send("_#{name}_callbacks")
186
+
187
+ if !self.class.skip_after_callbacks_if_terminated && callbacks.any? { |c| c.kind == :after }
188
+ ActiveSupport::Deprecation.warn(<<~EOM)
189
+ In Rails 6.2, `after_enqueue`/`after_perform` callbacks no longer run if `before_enqueue`/`before_perform` respectively halts with `throw :abort`.
190
+ To enable this behavior, uncomment the `config.active_job.skip_after_callbacks_if_terminated` config
191
+ in the new 6.1 framework defaults initializer.
192
+ EOM
193
+ end
194
+
195
+ super
196
+ end
157
197
  end
158
198
  end
@@ -85,6 +85,7 @@ module ActiveJob
85
85
  @priority = self.class.priority
86
86
  @executions = 0
87
87
  @exception_executions = {}
88
+ @timezone = Time.zone&.name
88
89
  end
89
90
  ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
90
91
 
@@ -101,7 +102,7 @@ module ActiveJob
101
102
  "executions" => executions,
102
103
  "exception_executions" => exception_executions,
103
104
  "locale" => I18n.locale.to_s,
104
- "timezone" => Time.zone.try(:name),
105
+ "timezone" => timezone,
105
106
  "enqueued_at" => Time.now.utc.iso8601
106
107
  }
107
108
  end
@@ -141,7 +142,7 @@ module ActiveJob
141
142
  self.executions = job_data["executions"]
142
143
  self.exception_executions = job_data["exception_executions"]
143
144
  self.locale = job_data["locale"] || I18n.locale.to_s
144
- self.timezone = job_data["timezone"] || Time.zone.try(:name)
145
+ self.timezone = job_data["timezone"] || Time.zone&.name
145
146
  self.enqueued_at = job_data["enqueued_at"]
146
147
  end
147
148
 
@@ -54,9 +54,9 @@ module ActiveJob
54
54
 
55
55
  run_callbacks :enqueue do
56
56
  if scheduled_at
57
- self.class.queue_adapter.enqueue_at self, scheduled_at
57
+ queue_adapter.enqueue_at self, scheduled_at
58
58
  else
59
- self.class.queue_adapter.enqueue self
59
+ queue_adapter.enqueue self
60
60
  end
61
61
 
62
62
  successfully_enqueued = true
@@ -65,17 +65,7 @@ module ActiveJob
65
65
  if successfully_enqueued
66
66
  self
67
67
  else
68
- if self.class.return_false_on_aborted_enqueue
69
- false
70
- else
71
- ActiveSupport::Deprecation.warn(
72
- "Rails 6.1 will return false when the enqueuing is aborted. Make sure your code doesn't depend on it" \
73
- " returning the instance of the job and set `config.active_job.return_false_on_aborted_enqueue = true`" \
74
- " to remove the deprecations."
75
- )
76
-
77
- self
78
- end
68
+ false
79
69
  end
80
70
  end
81
71
  end