activejob 6.0.3.3 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -149
- data/MIT-LICENSE +1 -1
- data/README.md +1 -3
- data/lib/active_job.rb +1 -1
- data/lib/active_job/base.rb +3 -0
- data/lib/active_job/callbacks.rb +44 -4
- data/lib/active_job/core.rb +3 -2
- data/lib/active_job/enqueuing.rb +3 -13
- data/lib/active_job/exceptions.rb +29 -20
- data/lib/active_job/execution.rb +9 -1
- data/lib/active_job/gem_version.rb +3 -3
- data/lib/active_job/instrumentation.rb +40 -0
- data/lib/active_job/log_subscriber.rb +140 -0
- data/lib/active_job/logging.rb +3 -132
- data/lib/active_job/queue_adapter.rb +3 -0
- data/lib/active_job/queue_adapters.rb +5 -1
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/test_adapter.rb +6 -2
- data/lib/active_job/queue_name.rb +2 -2
- data/lib/active_job/railtie.rb +4 -0
- data/lib/active_job/serializers.rb +4 -1
- data/lib/active_job/serializers/date_time_serializer.rb +1 -5
- data/lib/active_job/serializers/module_serializer.rb +20 -0
- data/lib/active_job/serializers/object_serializer.rb +1 -1
- data/lib/active_job/serializers/time_object_serializer.rb +13 -0
- data/lib/active_job/serializers/time_serializer.rb +1 -5
- data/lib/active_job/serializers/time_with_zone_serializer.rb +1 -5
- data/lib/active_job/test_helper.rb +81 -80
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35320cc54085adaeb2a5cdc283c0287992945e520ec24f2f6eb68690abe7f2c2
|
4
|
+
data.tar.gz: 26aa5b5976bb96e5571a66464b3d25d239a1197167b87a2673c33e67ded91013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf40eaaa0a1b5003bdecaecd29a5deb1060998f405677fd1114599fcc95285d1173c2da125f3e5f3557e2773a71a77e49919e39b67a6cd8cdeeb01db37db48b
|
7
|
+
data.tar.gz: aca36b4e3c1348d096dcd9f8e033f18705f648d5f3d092e9a6882b9fd8c6a24bc322bd417d0792c9f7af5c8bebb277250e5c552fdb8b2fce946a0cfefb671888
|
data/CHANGELOG.md
CHANGED
@@ -1,208 +1,141 @@
|
|
1
|
-
## Rails 6.
|
1
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Make `retry_job` return the job that was created.
|
4
4
|
|
5
|
+
*Rafael Mendonça França*
|
5
6
|
|
6
|
-
|
7
|
+
* Include `ActiveSupport::Testing::Assertions` in `ActiveJob::TestHelpers`.
|
7
8
|
|
8
|
-
*
|
9
|
+
*Mikkel Malmberg*
|
9
10
|
|
10
11
|
|
11
|
-
## Rails 6.0
|
12
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
12
13
|
|
13
|
-
*
|
14
|
+
* Recover nano precision when serializing `Time`, `TimeWithZone` and `DateTime` objects.
|
14
15
|
|
16
|
+
*Alan Tan*
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
* While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
|
19
|
-
`assert_enqueued_with`.
|
20
|
-
|
21
|
-
*Dmitry Polushkin*
|
22
|
-
|
23
|
-
* Add queue name support to Que adapter
|
24
|
-
|
25
|
-
*Brad Nauta*, *Wojciech Wnętrzak*
|
26
|
-
|
27
|
-
|
28
|
-
## Rails 6.0.2.2 (March 19, 2020) ##
|
29
|
-
|
30
|
-
* No changes.
|
31
|
-
|
32
|
-
|
33
|
-
## Rails 6.0.2.1 (December 18, 2019) ##
|
34
|
-
|
35
|
-
* No changes.
|
36
|
-
|
37
|
-
|
38
|
-
## Rails 6.0.2 (December 13, 2019) ##
|
39
|
-
|
40
|
-
* Allow Sidekiq access to the underlying job class.
|
41
|
-
|
42
|
-
By having access to the Active Job class, Sidekiq can get access to any `sidekiq_options` which
|
43
|
-
have been set on that Active Job type and serialize those options into Redis.
|
44
|
-
|
45
|
-
https://github.com/mperham/sidekiq/blob/master/Changes.md#60
|
46
|
-
|
47
|
-
*Mike Perham*
|
48
|
-
|
49
|
-
|
50
|
-
## Rails 6.0.1 (November 5, 2019) ##
|
51
|
-
|
52
|
-
* No changes.
|
53
|
-
|
54
|
-
|
55
|
-
## Rails 6.0.0 (August 16, 2019) ##
|
56
|
-
|
57
|
-
* `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
|
58
|
-
|
59
|
-
*Vlado Cingel*
|
60
|
-
|
61
|
-
|
62
|
-
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
63
|
-
|
64
|
-
* No changes.
|
18
|
+
* Deprecate `config.active_job.return_false_on_aborted_enqueue`.
|
65
19
|
|
20
|
+
*Rafael Mendonça França*
|
66
21
|
|
67
|
-
|
22
|
+
* Return `false` when enqueuing a job is aborted.
|
68
23
|
|
69
|
-
*
|
70
|
-
|
71
|
-
*Patrik Bóna*
|
72
|
-
|
73
|
-
* Make job argument assertions with `Time`, `ActiveSupport::TimeWithZone`, and `DateTime` work by dropping microseconds. Microsecond precision is lost during serialization.
|
74
|
-
|
75
|
-
*Gannon McGibbon*
|
24
|
+
*Rafael Mendonça França*
|
76
25
|
|
26
|
+
* While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with
|
27
|
+
`assert_enqueued_with`.
|
77
28
|
|
78
|
-
|
29
|
+
*Dmitry Polushkin*
|
79
30
|
|
80
|
-
*
|
31
|
+
* `ActiveJob::TestCase#perform_enqueued_jobs` without a block removes performed jobs from the queue.
|
81
32
|
|
33
|
+
That way the helper can be called multiple times and not perform a job invocation multiple times.
|
82
34
|
|
83
|
-
|
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
|
+
```
|
84
43
|
|
85
|
-
|
44
|
+
*Étienne Barrié*
|
86
45
|
|
46
|
+
* `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
|
87
47
|
|
88
|
-
|
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.
|
89
51
|
|
90
|
-
|
52
|
+
This change only affects `perform_enqueued_jobs` when no block is given.
|
91
53
|
|
92
|
-
|
93
|
-
`config.active_job.return_false_on_aborted_enqueue`.
|
54
|
+
*Edouard Chin*
|
94
55
|
|
95
|
-
|
56
|
+
* Add queue name support to Que adapter.
|
96
57
|
|
97
|
-
*
|
58
|
+
*Brad Nauta*, *Wojciech Wnętrzak*
|
98
59
|
|
99
|
-
|
100
|
-
shared between all executions of a job.
|
60
|
+
* Don't run `after_enqueue` and `after_perform` callbacks if the callback chain is halted.
|
101
61
|
|
102
|
-
|
62
|
+
class MyJob < ApplicationJob
|
63
|
+
before_enqueue { throw(:abort) }
|
64
|
+
after_enqueue { # won't enter here anymore }
|
65
|
+
end
|
103
66
|
|
104
|
-
|
105
|
-
|
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`.
|
106
71
|
|
107
72
|
*Edouard Chin*
|
108
73
|
|
109
|
-
*
|
74
|
+
* Fix enqueuing and performing incorrect logging message.
|
110
75
|
|
111
|
-
|
76
|
+
Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
|
112
77
|
|
113
|
-
|
114
|
-
|
78
|
+
```ruby
|
79
|
+
class MyJob < ApplicationJob
|
80
|
+
before_enqueue { throw(:abort) }
|
81
|
+
end
|
115
82
|
|
116
|
-
|
83
|
+
MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.
|
84
|
+
```
|
117
85
|
|
118
|
-
|
119
|
-
|
120
|
-
matches your expectations.
|
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)
|
121
88
|
|
122
89
|
*Edouard Chin*
|
123
90
|
|
124
|
-
*
|
125
|
-
|
126
|
-
*Ricardo Díaz*
|
91
|
+
* Add an option to disable logging of the job arguments when enqueuing and executing the job.
|
127
92
|
|
128
|
-
|
93
|
+
class SensitiveJob < ApplicationJob
|
94
|
+
self.log_arguments = false
|
129
95
|
|
130
|
-
|
96
|
+
def perform(my_sensitive_argument)
|
97
|
+
end
|
98
|
+
end
|
131
99
|
|
132
|
-
|
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.
|
133
102
|
|
134
|
-
*
|
103
|
+
*Rafael Mendonça França*
|
135
104
|
|
136
|
-
*
|
137
|
-
without a block should respect passed `:except`, `:only`, and `:queue` options.
|
105
|
+
* Changes in `queue_name_prefix` of a job no longer affects all other jobs.
|
138
106
|
|
139
|
-
|
107
|
+
Fixes #37084.
|
140
108
|
|
141
|
-
*
|
109
|
+
*Lucas Mansur*
|
142
110
|
|
143
|
-
|
144
|
-
|
145
|
-
* Allow `perform_enqueued_jobs` to be called without a block.
|
146
|
-
|
147
|
-
Performs all of the jobs that have been enqueued up to this point in the test.
|
111
|
+
* Allow `Class` and `Module` instances to be serialized.
|
148
112
|
|
149
113
|
*Kevin Deisz*
|
150
114
|
|
151
|
-
*
|
152
|
-
|
153
|
-
Improves timing accuracy over the old after callback by including
|
154
|
-
time spent writing to the adapter's IO implementation.
|
155
|
-
|
156
|
-
*Zach Kemp*
|
115
|
+
* Log potential matches in `assert_enqueued_with` and `assert_performed_with`.
|
157
116
|
|
158
|
-
*
|
117
|
+
*Gareth du Plooy*
|
159
118
|
|
160
|
-
|
161
|
-
```
|
162
|
-
def test_assert_enqueued_with
|
163
|
-
MyJob.perform_later(1,2,3)
|
164
|
-
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
|
165
|
-
|
166
|
-
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
|
167
|
-
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
|
168
|
-
end
|
169
|
-
```
|
170
|
-
|
171
|
-
*bogdanvlviv*
|
172
|
-
|
173
|
-
* Allow passing multiple exceptions to `retry_on`, and `discard_on`.
|
174
|
-
|
175
|
-
*George Claghorn*
|
176
|
-
|
177
|
-
* Pass the error instance as the second parameter of block executed by `discard_on`.
|
119
|
+
* Add `at` argument to the `perform_enqueued_jobs` test helper.
|
178
120
|
|
179
|
-
|
121
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
180
122
|
|
181
|
-
|
182
|
-
|
183
|
-
* Remove support for Qu gem.
|
184
|
-
|
185
|
-
Reasons are that the Qu gem wasn't compatible since Rails 5.1,
|
186
|
-
gem development was stopped in 2014 and maintainers have
|
187
|
-
confirmed its demise. See issue #32273
|
188
|
-
|
189
|
-
*Alberto Almagro*
|
190
|
-
|
191
|
-
* Add support for timezones to Active Job.
|
192
|
-
|
193
|
-
Record what was the current timezone in effect when the job was
|
194
|
-
enqueued and then restore when the job is executed in same way
|
195
|
-
that the current locale is recorded and restored.
|
123
|
+
* `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
|
196
124
|
|
197
|
-
*
|
125
|
+
*Vlado Cingel*
|
198
126
|
|
199
|
-
*
|
127
|
+
* Add jitter to `ActiveJob::Exceptions.retry_on`.
|
200
128
|
|
201
|
-
|
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`.
|
202
133
|
|
203
|
-
|
134
|
+
```ruby
|
135
|
+
retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)
|
136
|
+
```
|
204
137
|
|
205
|
-
*
|
138
|
+
*Anthony Ross*
|
206
139
|
|
207
140
|
|
208
|
-
Please check [
|
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
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:
|
data/lib/active_job.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2014-
|
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
|
data/lib/active_job/base.rb
CHANGED
@@ -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
|
|
data/lib/active_job/callbacks.rb
CHANGED
@@ -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
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
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
|
data/lib/active_job/core.rb
CHANGED
@@ -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" =>
|
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
|
145
|
+
self.timezone = job_data["timezone"] || Time.zone&.name
|
145
146
|
self.enqueued_at = job_data["enqueued_at"]
|
146
147
|
end
|
147
148
|
|