activejob 5.2.4.1 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +104 -35
- data/MIT-LICENSE +1 -1
- data/README.md +17 -10
- data/lib/active_job.rb +2 -1
- data/lib/active_job/arguments.rb +40 -28
- data/lib/active_job/base.rb +3 -1
- data/lib/active_job/callbacks.rb +4 -1
- data/lib/active_job/core.rb +38 -21
- data/lib/active_job/enqueuing.rb +26 -5
- data/lib/active_job/exceptions.rb +40 -17
- data/lib/active_job/execution.rb +1 -1
- data/lib/active_job/gem_version.rb +4 -4
- data/lib/active_job/logging.rb +40 -9
- data/lib/active_job/queue_adapter.rb +2 -0
- data/lib/active_job/queue_adapters.rb +8 -10
- data/lib/active_job/queue_adapters/async_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/backburner_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/test_adapter.rb +22 -8
- data/lib/active_job/queue_name.rb +21 -1
- data/lib/active_job/railtie.rb +16 -1
- data/lib/active_job/serializers.rb +63 -0
- data/lib/active_job/serializers/date_serializer.rb +21 -0
- data/lib/active_job/serializers/date_time_serializer.rb +21 -0
- data/lib/active_job/serializers/duration_serializer.rb +24 -0
- data/lib/active_job/serializers/object_serializer.rb +54 -0
- data/lib/active_job/serializers/symbol_serializer.rb +21 -0
- data/lib/active_job/serializers/time_serializer.rb +21 -0
- data/lib/active_job/serializers/time_with_zone_serializer.rb +21 -0
- data/lib/active_job/test_helper.rb +278 -57
- data/lib/active_job/timezones.rb +13 -0
- data/lib/active_job/translation.rb +1 -1
- data/lib/rails/generators/job/job_generator.rb +4 -0
- metadata +21 -10
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 480894177303ccd2e660bcbff34d6b3f4d833df45b49d47ad93019775762585c
|
4
|
+
data.tar.gz: f9a07feb5a14b4aeed27e0b3fe9abacbb60eb8da4f082f6e2680168be354899f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ac8458fc64c6d2cb111e605663de4d0db030a5ac7328de2b1528cc7777999c161edd2533926e1411adcb361ce572fd330e2ec58a5e42bdf0770e869e08bf9b
|
7
|
+
data.tar.gz: 91b4621647aba7d7082db93799d0e584807b72feaddeca120eac2d978c09f5d36793d9a1270fdafa2f2805d2c0ec06b588e4ceed5268c05204424087a106529c
|
data/CHANGELOG.md
CHANGED
@@ -1,32 +1,61 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails
|
6
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
7
|
+
|
8
|
+
* `assert_enqueued_with` and `assert_performed_with` can now test jobs with relative delay.
|
9
|
+
|
10
|
+
*Vlado Cingel*
|
11
|
+
|
12
|
+
|
13
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
7
14
|
|
8
15
|
* No changes.
|
9
16
|
|
10
17
|
|
11
|
-
## Rails
|
18
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
19
|
+
|
20
|
+
* Use individual execution counters when calculating retry delay.
|
21
|
+
|
22
|
+
*Patrik Bóna*
|
23
|
+
|
24
|
+
* Make job argument assertions with `Time`, `ActiveSupport::TimeWithZone`, and `DateTime` work by dropping microseconds. Microsecond precision is lost during serialization.
|
25
|
+
|
26
|
+
*Gannon McGibbon*
|
27
|
+
|
28
|
+
|
29
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
12
30
|
|
13
31
|
* No changes.
|
14
32
|
|
15
33
|
|
16
|
-
## Rails
|
34
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
17
35
|
|
18
36
|
* No changes.
|
19
37
|
|
20
38
|
|
21
|
-
## Rails
|
39
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
40
|
+
|
41
|
+
* Return false instead of the job instance when `enqueue` is aborted.
|
42
|
+
|
43
|
+
This will be the behavior in Rails 6.1 but it can be controlled now with
|
44
|
+
`config.active_job.return_false_on_aborted_enqueue`.
|
22
45
|
|
23
|
-
*
|
46
|
+
*Kir Shatrov*
|
24
47
|
|
25
|
-
|
48
|
+
* Keep executions for each specific declaration
|
26
49
|
|
27
|
-
|
50
|
+
Each `retry_on` declaration has now its own specific executions counter. Before it was
|
51
|
+
shared between all executions of a job.
|
28
52
|
|
29
|
-
*
|
53
|
+
*Alberto Almagro*
|
54
|
+
|
55
|
+
* Allow all assertion helpers that have a `only` and `except` keyword to accept
|
56
|
+
Procs.
|
57
|
+
|
58
|
+
*Edouard Chin*
|
30
59
|
|
31
60
|
* Restore `HashWithIndifferentAccess` support to `ActiveJob::Arguments.deserialize`.
|
32
61
|
|
@@ -37,27 +66,64 @@
|
|
37
66
|
|
38
67
|
*Alan Wu*
|
39
68
|
|
40
|
-
*
|
69
|
+
* Allow `assert_enqueued_with`/`assert_performed_with` methods to accept
|
70
|
+
a proc for the `args` argument. This is useful to check if only a subset of arguments
|
71
|
+
matches your expectations.
|
41
72
|
|
42
|
-
|
43
|
-
Therefore, if an error occurs with deserialize, it retries indefinitely.
|
73
|
+
*Edouard Chin*
|
44
74
|
|
45
|
-
|
75
|
+
* `ActionDispatch::IntegrationTest` includes `ActiveJob::TestHelper` module by default.
|
76
|
+
|
77
|
+
*Ricardo Díaz*
|
46
78
|
|
79
|
+
* Added `enqueue_retry.active_job`, `retry_stopped.active_job`, and `discard.active_job` hooks.
|
47
80
|
|
48
|
-
|
81
|
+
*steves*
|
49
82
|
|
50
|
-
*
|
83
|
+
* Allow `assert_performed_with` to be called without a block.
|
51
84
|
|
52
|
-
|
53
|
-
information that should not be accessible to them.
|
85
|
+
*bogdanvlviv*
|
54
86
|
|
55
|
-
|
87
|
+
* Execution of `assert_performed_jobs`, and `assert_no_performed_jobs`
|
88
|
+
without a block should respect passed `:except`, `:only`, and `:queue` options.
|
56
89
|
|
57
|
-
*
|
90
|
+
*bogdanvlviv*
|
58
91
|
|
92
|
+
* Allow `:queue` option to job assertions and helpers.
|
59
93
|
|
60
|
-
|
94
|
+
*bogdanvlviv*
|
95
|
+
|
96
|
+
* Allow `perform_enqueued_jobs` to be called without a block.
|
97
|
+
|
98
|
+
Performs all of the jobs that have been enqueued up to this point in the test.
|
99
|
+
|
100
|
+
*Kevin Deisz*
|
101
|
+
|
102
|
+
* Move `enqueue`/`enqueue_at` notifications to an around callback.
|
103
|
+
|
104
|
+
Improves timing accuracy over the old after callback by including
|
105
|
+
time spent writing to the adapter's IO implementation.
|
106
|
+
|
107
|
+
*Zach Kemp*
|
108
|
+
|
109
|
+
* Allow call `assert_enqueued_with` with no block.
|
110
|
+
|
111
|
+
Example:
|
112
|
+
```
|
113
|
+
def test_assert_enqueued_with
|
114
|
+
MyJob.perform_later(1,2,3)
|
115
|
+
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
|
116
|
+
|
117
|
+
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
|
118
|
+
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
*bogdanvlviv*
|
123
|
+
|
124
|
+
* Allow passing multiple exceptions to `retry_on`, and `discard_on`.
|
125
|
+
|
126
|
+
*George Claghorn*
|
61
127
|
|
62
128
|
* Pass the error instance as the second parameter of block executed by `discard_on`.
|
63
129
|
|
@@ -65,26 +131,29 @@
|
|
65
131
|
|
66
132
|
*Yuji Yaginuma*
|
67
133
|
|
68
|
-
|
134
|
+
* Remove support for Qu gem.
|
69
135
|
|
70
|
-
|
136
|
+
Reasons are that the Qu gem wasn't compatible since Rails 5.1,
|
137
|
+
gem development was stopped in 2014 and maintainers have
|
138
|
+
confirmed its demise. See issue #32273
|
71
139
|
|
72
|
-
|
140
|
+
*Alberto Almagro*
|
141
|
+
|
142
|
+
* Add support for timezones to Active Job.
|
143
|
+
|
144
|
+
Record what was the current timezone in effect when the job was
|
145
|
+
enqueued and then restore when the job is executed in same way
|
146
|
+
that the current locale is recorded and restored.
|
147
|
+
|
148
|
+
*Andrew White*
|
73
149
|
|
74
|
-
|
75
|
-
discard_on(CustomAppException) do |job, exception|
|
76
|
-
ExceptionNotifier.caught(exception)
|
77
|
-
end
|
150
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
78
151
|
|
79
|
-
|
80
|
-
# Might raise CustomAppException for something domain specific
|
81
|
-
end
|
82
|
-
end
|
152
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
83
153
|
|
84
|
-
|
154
|
+
* Add support to define custom argument serializers.
|
85
155
|
|
86
|
-
*
|
156
|
+
*Evgenii Pecherkin*, *Rafael Mendonça França*
|
87
157
|
|
88
|
-
*Jeremy Daer*
|
89
158
|
|
90
|
-
Please check [5-
|
159
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activejob/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Active Job
|
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
|
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
|
24
|
+
To learn how to use your preferred queuing backend see its adapter
|
24
25
|
documentation at
|
25
|
-
[ActiveJob::QueueAdapters](
|
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
|
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,11 +83,17 @@ 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
|
86
|
+
## Supported queuing systems
|
86
87
|
|
87
|
-
Active Job has built-in adapters for multiple
|
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](
|
90
|
+
see the API Documentation for [ActiveJob::QueueAdapters](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
|
91
|
+
|
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).
|
90
97
|
|
91
98
|
## Auxiliary gems
|
92
99
|
|
@@ -102,7 +109,7 @@ The latest version of Active Job can be installed with RubyGems:
|
|
102
109
|
|
103
110
|
Source code can be downloaded as part of the Rails project on GitHub:
|
104
111
|
|
105
|
-
* https://github.com/rails/rails/tree/
|
112
|
+
* https://github.com/rails/rails/tree/master/activejob
|
106
113
|
|
107
114
|
## License
|
108
115
|
|
@@ -115,7 +122,7 @@ Active Job is released under the MIT license:
|
|
115
122
|
|
116
123
|
API documentation is at:
|
117
124
|
|
118
|
-
*
|
125
|
+
* https://api.rubyonrails.org
|
119
126
|
|
120
127
|
Bug reports for the Ruby on Rails project can be filed here:
|
121
128
|
|
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-2019 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
|
data/lib/active_job/arguments.rb
CHANGED
@@ -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
|
18
|
-
#
|
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
|
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
|
-
#
|
27
|
-
|
28
|
-
|
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.
|
38
|
-
# as-is. Arrays/Hashes are
|
39
|
-
# All other types are deserialized using
|
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
|
-
|
56
|
+
WITH_INDIFFERENT_ACCESS_KEY = "_aj_hash_with_indifferent_access"
|
49
57
|
# :nodoc:
|
50
|
-
|
58
|
+
OBJECT_SERIALIZER_KEY = "_aj_serialized"
|
59
|
+
|
51
60
|
# :nodoc:
|
52
|
-
|
53
|
-
|
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 *
|
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
|
-
|
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 *
|
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
|
data/lib/active_job/base.rb
CHANGED
@@ -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
|
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)
|