activejob 7.0.4 → 7.1.5.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 +222 -94
- data/MIT-LICENSE +1 -1
- data/README.md +4 -4
- data/lib/active_job/arguments.rb +28 -31
- data/lib/active_job/base.rb +1 -1
- data/lib/active_job/callbacks.rb +3 -5
- data/lib/active_job/configured_job.rb +4 -0
- data/lib/active_job/core.rb +26 -6
- data/lib/active_job/deprecator.rb +7 -0
- data/lib/active_job/enqueuing.rb +31 -3
- data/lib/active_job/exceptions.rb +52 -8
- data/lib/active_job/execution.rb +11 -2
- data/lib/active_job/gem_version.rb +4 -4
- data/lib/active_job/instrumentation.rb +18 -10
- data/lib/active_job/log_subscriber.rb +81 -9
- data/lib/active_job/queue_adapter.rb +13 -2
- data/lib/active_job/queue_adapters/async_adapter.rb +2 -2
- data/lib/active_job/queue_adapters/backburner_adapter.rb +7 -3
- data/lib/active_job/queue_adapters/delayed_job_adapter.rb +3 -1
- data/lib/active_job/queue_adapters/inline_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/queue_classic_adapter.rb +4 -4
- data/lib/active_job/queue_adapters/resque_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +42 -14
- data/lib/active_job/queue_adapters/sneakers_adapter.rb +1 -1
- data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +3 -3
- data/lib/active_job/queue_adapters/test_adapter.rb +3 -3
- data/lib/active_job/queue_adapters.rb +8 -7
- data/lib/active_job/queue_name.rb +1 -2
- data/lib/active_job/queue_priority.rb +18 -1
- data/lib/active_job/railtie.rb +26 -7
- data/lib/active_job/serializers/big_decimal_serializer.rb +22 -0
- data/lib/active_job/serializers/duration_serializer.rb +4 -2
- data/lib/active_job/serializers/time_with_zone_serializer.rb +11 -2
- data/lib/active_job/serializers.rb +7 -3
- data/lib/active_job/test_helper.rb +32 -14
- data/lib/active_job/version.rb +1 -1
- data/lib/active_job.rb +29 -4
- data/lib/rails/generators/job/USAGE +19 -0
- data/lib/rails/generators/job/job_generator.rb +6 -2
- data/lib/rails/generators/job/templates/job.rb.tt +1 -1
- metadata +14 -12
- data/lib/active_job/queue_adapters/que_adapter.rb +0 -61
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
gem "sidekiq", ">= 4.1.0"
|
3
4
|
require "sidekiq"
|
4
5
|
|
5
6
|
module ActiveJob
|
6
7
|
module QueueAdapters
|
7
|
-
#
|
8
|
+
# = Sidekiq adapter for Active Job
|
8
9
|
#
|
9
10
|
# Simple, efficient background processing for Ruby. Sidekiq uses threads to
|
10
11
|
# handle many jobs at the same time in the same process. It does not
|
11
|
-
# require Rails but will integrate tightly with it to make background
|
12
|
+
# require \Rails but will integrate tightly with it to make background
|
12
13
|
# processing dead simple.
|
13
14
|
#
|
14
15
|
# Read more about Sidekiq {here}[http://sidekiq.org].
|
@@ -18,21 +19,48 @@ module ActiveJob
|
|
18
19
|
# Rails.application.config.active_job.queue_adapter = :sidekiq
|
19
20
|
class SidekiqAdapter
|
20
21
|
def enqueue(job) # :nodoc:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"queue" => job.queue_name,
|
26
|
-
"args" => [ job.serialize ]
|
22
|
+
job.provider_job_id = JobWrapper.set(
|
23
|
+
wrapped: job.class,
|
24
|
+
queue: job.queue_name
|
25
|
+
).perform_async(job.serialize)
|
27
26
|
end
|
28
27
|
|
29
28
|
def enqueue_at(job, timestamp) # :nodoc:
|
30
|
-
job.provider_job_id =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
job.provider_job_id = JobWrapper.set(
|
30
|
+
wrapped: job.class,
|
31
|
+
queue: job.queue_name,
|
32
|
+
).perform_at(timestamp, job.serialize)
|
33
|
+
end
|
34
|
+
|
35
|
+
def enqueue_all(jobs) # :nodoc:
|
36
|
+
enqueued_count = 0
|
37
|
+
jobs.group_by(&:class).each do |job_class, same_class_jobs|
|
38
|
+
same_class_jobs.group_by(&:queue_name).each do |queue, same_class_and_queue_jobs|
|
39
|
+
immediate_jobs, scheduled_jobs = same_class_and_queue_jobs.partition { |job| job.scheduled_at.nil? }
|
40
|
+
|
41
|
+
if immediate_jobs.any?
|
42
|
+
jids = Sidekiq::Client.push_bulk(
|
43
|
+
"class" => JobWrapper,
|
44
|
+
"wrapped" => job_class,
|
45
|
+
"queue" => queue,
|
46
|
+
"args" => immediate_jobs.map { |job| [job.serialize] },
|
47
|
+
)
|
48
|
+
enqueued_count += jids.compact.size
|
49
|
+
end
|
50
|
+
|
51
|
+
if scheduled_jobs.any?
|
52
|
+
jids = Sidekiq::Client.push_bulk(
|
53
|
+
"class" => JobWrapper,
|
54
|
+
"wrapped" => job_class,
|
55
|
+
"queue" => queue,
|
56
|
+
"args" => scheduled_jobs.map { |job| [job.serialize] },
|
57
|
+
"at" => scheduled_jobs.map { |job| job.scheduled_at&.to_f }
|
58
|
+
)
|
59
|
+
enqueued_count += jids.compact.size
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
enqueued_count
|
36
64
|
end
|
37
65
|
|
38
66
|
class JobWrapper # :nodoc:
|
@@ -5,7 +5,7 @@ require "monitor"
|
|
5
5
|
|
6
6
|
module ActiveJob
|
7
7
|
module QueueAdapters
|
8
|
-
#
|
8
|
+
# = Sneakers adapter for Active Job
|
9
9
|
#
|
10
10
|
# A high-performance RabbitMQ background processing framework for Ruby.
|
11
11
|
# Sneakers is being used in production for both I/O and CPU intensive
|
@@ -4,13 +4,13 @@ require "sucker_punch"
|
|
4
4
|
|
5
5
|
module ActiveJob
|
6
6
|
module QueueAdapters
|
7
|
-
#
|
7
|
+
# = Sucker Punch adapter for Active Job
|
8
8
|
#
|
9
9
|
# Sucker Punch is a single-process Ruby asynchronous processing library.
|
10
10
|
# This reduces the cost of hosting on a service like Heroku along
|
11
11
|
# with the memory footprint of having to maintain additional jobs if
|
12
12
|
# hosting on a dedicated server. All queues can run within a
|
13
|
-
# single application (e.g. Rails, Sinatra, etc.) process.
|
13
|
+
# single application (e.g. \Rails, Sinatra, etc.) process.
|
14
14
|
#
|
15
15
|
# Read more about Sucker Punch {here}[https://github.com/brandonhilkert/sucker_punch].
|
16
16
|
#
|
@@ -33,7 +33,7 @@ module ActiveJob
|
|
33
33
|
delay = timestamp - Time.current.to_f
|
34
34
|
JobWrapper.perform_in delay, job.serialize
|
35
35
|
else
|
36
|
-
raise NotImplementedError, "sucker_punch 1.0 does not support `
|
36
|
+
raise NotImplementedError, "sucker_punch 1.0 does not support `enqueue_at`. Please upgrade to version ~> 2.0.0 to enable this behavior."
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module ActiveJob
|
4
4
|
module QueueAdapters
|
5
|
-
#
|
5
|
+
# = Test adapter for Active Job
|
6
6
|
#
|
7
7
|
# The test adapter should be used only in testing. Along with
|
8
8
|
# ActiveJob::TestCase and ActiveJob::TestHelper
|
9
|
-
# it makes a great tool to test your Rails application.
|
9
|
+
# it makes a great tool to test your \Rails application.
|
10
10
|
#
|
11
11
|
# To use the test adapter set +queue_adapter+ config to +:test+.
|
12
12
|
#
|
@@ -59,7 +59,7 @@ module ActiveJob
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def filtered_time?(job)
|
62
|
-
job.scheduled_at > at
|
62
|
+
job.scheduled_at > at if at && job.scheduled_at
|
63
63
|
end
|
64
64
|
|
65
65
|
def filtered_queue?(job)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveJob
|
4
|
-
#
|
4
|
+
# = Active Job adapters
|
5
5
|
#
|
6
6
|
# Active Job has adapters for the following queuing backends:
|
7
7
|
#
|
@@ -13,10 +13,14 @@ module ActiveJob
|
|
13
13
|
# * {Sidekiq}[https://sidekiq.org]
|
14
14
|
# * {Sneakers}[https://github.com/jondot/sneakers]
|
15
15
|
# * {Sucker Punch}[https://github.com/brandonhilkert/sucker_punch]
|
16
|
-
# * {Active Job Async Job}[https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/AsyncAdapter.html]
|
17
|
-
# * {Active Job Inline}[https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]
|
18
16
|
# * Please Note: We are not accepting pull requests for new adapters. See the {README}[link:files/activejob/README_md.html] for more details.
|
19
17
|
#
|
18
|
+
# For testing and development Active Job has three built-in adapters:
|
19
|
+
#
|
20
|
+
# * {Active Job Async}[https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/AsyncAdapter.html]
|
21
|
+
# * {Active Job Inline}[https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]
|
22
|
+
# * {Active Job Test}[https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/TestAdapter.html]
|
23
|
+
#
|
20
24
|
# === Backends Features
|
21
25
|
#
|
22
26
|
# | | Async | Queues | Delayed | Priorities | Timeout | Retries |
|
@@ -31,6 +35,7 @@ module ActiveJob
|
|
31
35
|
# | Sucker Punch | Yes | Yes | Yes | No | No | No |
|
32
36
|
# | Active Job Async | Yes | Yes | Yes | No | No | No |
|
33
37
|
# | Active Job Inline | No | Yes | N/A | N/A | N/A | N/A |
|
38
|
+
# | Active Job Test | No | Yes | N/A | N/A | N/A | N/A |
|
34
39
|
#
|
35
40
|
# ==== Async
|
36
41
|
#
|
@@ -106,10 +111,6 @@ module ActiveJob
|
|
106
111
|
# N/A: The adapter does not run in a separate process, and therefore doesn't
|
107
112
|
# support retries.
|
108
113
|
#
|
109
|
-
# === Async and Inline Queue Adapters
|
110
|
-
#
|
111
|
-
# Active Job has two built-in queue adapters intended for development and
|
112
|
-
# testing: +:async+ and +:inline+.
|
113
114
|
module QueueAdapters
|
114
115
|
extend ActiveSupport::Autoload
|
115
116
|
|
@@ -19,8 +19,7 @@ module ActiveJob
|
|
19
19
|
# end
|
20
20
|
#
|
21
21
|
# Can be given a block that will evaluate in the context of the job
|
22
|
-
#
|
23
|
-
# can be applied:
|
22
|
+
# so that a dynamic queue name can be applied:
|
24
23
|
#
|
25
24
|
# class PublishToFeedJob < ApplicationJob
|
26
25
|
# queue_as do
|
@@ -18,7 +18,24 @@ module ActiveJob
|
|
18
18
|
# end
|
19
19
|
# end
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# Can be given a block that will evaluate in the context of the job
|
22
|
+
# so that a dynamic priority can be applied:
|
23
|
+
#
|
24
|
+
# class PublishToFeedJob < ApplicationJob
|
25
|
+
# queue_with_priority do
|
26
|
+
# post = self.arguments.first
|
27
|
+
#
|
28
|
+
# if post.paid?
|
29
|
+
# 10
|
30
|
+
# else
|
31
|
+
# 50
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def perform(post)
|
36
|
+
# post.to_feed!
|
37
|
+
# end
|
38
|
+
# end
|
22
39
|
def queue_with_priority(priority = nil, &block)
|
23
40
|
if block_given?
|
24
41
|
self.priority = block
|
data/lib/active_job/railtie.rb
CHANGED
@@ -10,6 +10,10 @@ module ActiveJob
|
|
10
10
|
config.active_job.custom_serializers = []
|
11
11
|
config.active_job.log_query_tags_around_perform = true
|
12
12
|
|
13
|
+
initializer "active_job.deprecator", before: :load_environment_config do |app|
|
14
|
+
app.deprecators[:active_job] = ActiveJob.deprecator
|
15
|
+
end
|
16
|
+
|
13
17
|
initializer "active_job.logger" do
|
14
18
|
ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger }
|
15
19
|
end
|
@@ -25,6 +29,15 @@ module ActiveJob
|
|
25
29
|
options = app.config.active_job
|
26
30
|
options.queue_adapter ||= :async
|
27
31
|
|
32
|
+
config.after_initialize do
|
33
|
+
options.each do |k, v|
|
34
|
+
k = "#{k}="
|
35
|
+
if ActiveJob.respond_to?(k)
|
36
|
+
ActiveJob.send(k, v)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
28
41
|
ActiveSupport.on_load(:active_job) do
|
29
42
|
# Configs used in other initializers
|
30
43
|
options = options.except(
|
@@ -32,19 +45,19 @@ module ActiveJob
|
|
32
45
|
:custom_serializers
|
33
46
|
)
|
34
47
|
|
35
|
-
options.each do
|
48
|
+
options.each do |k, v|
|
36
49
|
k = "#{k}="
|
37
|
-
|
50
|
+
if ActiveJob.respond_to?(k)
|
51
|
+
ActiveJob.send(k, v)
|
52
|
+
elsif respond_to? k
|
53
|
+
send(k, v)
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
41
58
|
ActiveSupport.on_load(:action_dispatch_integration_test) do
|
42
59
|
include ActiveJob::TestHelper
|
43
60
|
end
|
44
|
-
|
45
|
-
ActiveSupport.on_load(:active_record) do
|
46
|
-
self.destroy_association_async_job = ActiveRecord::DestroyAssociationAsyncJob
|
47
|
-
end
|
48
61
|
end
|
49
62
|
|
50
63
|
initializer "active_job.set_reloader_hook" do |app|
|
@@ -63,12 +76,18 @@ module ActiveJob
|
|
63
76
|
app.config.active_job.log_query_tags_around_perform
|
64
77
|
|
65
78
|
if query_logs_tags_enabled
|
66
|
-
app.config.active_record.query_log_tags
|
79
|
+
app.config.active_record.query_log_tags |= [:job]
|
67
80
|
|
68
81
|
ActiveSupport.on_load(:active_record) do
|
69
82
|
ActiveRecord::QueryLogs.taggings[:job] = ->(context) { context[:job].class.name if context[:job] }
|
70
83
|
end
|
71
84
|
end
|
72
85
|
end
|
86
|
+
|
87
|
+
initializer "active_job.backtrace_cleaner" do
|
88
|
+
ActiveSupport.on_load(:active_job) do
|
89
|
+
LogSubscriber.backtrace_cleaner = ::Rails.backtrace_cleaner
|
90
|
+
end
|
91
|
+
end
|
73
92
|
end
|
74
93
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bigdecimal"
|
4
|
+
|
5
|
+
module ActiveJob
|
6
|
+
module Serializers
|
7
|
+
class BigDecimalSerializer < ObjectSerializer # :nodoc:
|
8
|
+
def serialize(big_decimal)
|
9
|
+
super("value" => big_decimal.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def deserialize(hash)
|
13
|
+
BigDecimal(hash["value"])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def klass
|
18
|
+
BigDecimal
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,14 +4,16 @@ module ActiveJob
|
|
4
4
|
module Serializers
|
5
5
|
class DurationSerializer < ObjectSerializer # :nodoc:
|
6
6
|
def serialize(duration)
|
7
|
+
# Ideally duration.parts would be wrapped in an array before passing to Arguments.serialize,
|
8
|
+
# but we continue passing the bare hash for backwards compatibility:
|
7
9
|
super("value" => duration.value, "parts" => Arguments.serialize(duration.parts))
|
8
10
|
end
|
9
11
|
|
10
12
|
def deserialize(hash)
|
11
13
|
value = hash["value"]
|
12
14
|
parts = Arguments.deserialize(hash["parts"])
|
13
|
-
|
14
|
-
klass.new(value, parts)
|
15
|
+
# `parts` is originally a hash, but will have been flattened to an array by Arguments.serialize
|
16
|
+
klass.new(value, parts.to_h)
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
@@ -2,9 +2,18 @@
|
|
2
2
|
|
3
3
|
module ActiveJob
|
4
4
|
module Serializers
|
5
|
-
class TimeWithZoneSerializer <
|
5
|
+
class TimeWithZoneSerializer < ObjectSerializer # :nodoc:
|
6
|
+
NANO_PRECISION = 9
|
7
|
+
|
8
|
+
def serialize(time_with_zone)
|
9
|
+
super(
|
10
|
+
"value" => time_with_zone.iso8601(NANO_PRECISION),
|
11
|
+
"time_zone" => time_with_zone.time_zone.tzinfo.name
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
6
15
|
def deserialize(hash)
|
7
|
-
Time.iso8601(hash["value"]).in_time_zone
|
16
|
+
Time.iso8601(hash["value"]).in_time_zone(hash["time_zone"] || Time.zone)
|
8
17
|
end
|
9
18
|
|
10
19
|
private
|
@@ -3,7 +3,9 @@
|
|
3
3
|
require "set"
|
4
4
|
|
5
5
|
module ActiveJob
|
6
|
-
#
|
6
|
+
# = Active Job \Serializers
|
7
|
+
#
|
8
|
+
# The +ActiveJob::Serializers+ module is used to store a list of known serializers
|
7
9
|
# and to add new ones. It also has helpers to serialize/deserialize objects.
|
8
10
|
module Serializers # :nodoc:
|
9
11
|
extend ActiveSupport::Autoload
|
@@ -18,6 +20,7 @@ module ActiveJob
|
|
18
20
|
autoload :TimeSerializer
|
19
21
|
autoload :ModuleSerializer
|
20
22
|
autoload :RangeSerializer
|
23
|
+
autoload :BigDecimalSerializer
|
21
24
|
|
22
25
|
mattr_accessor :_additional_serializers
|
23
26
|
self._additional_serializers = Set.new
|
@@ -25,7 +28,7 @@ module ActiveJob
|
|
25
28
|
class << self
|
26
29
|
# Returns serialized representative of the passed object.
|
27
30
|
# Will look up through all known serializers.
|
28
|
-
# Raises
|
31
|
+
# Raises ActiveJob::SerializationError if it can't find a proper serializer.
|
29
32
|
def serialize(argument)
|
30
33
|
serializer = serializers.detect { |s| s.serialize?(argument) }
|
31
34
|
raise SerializationError.new("Unsupported argument type: #{argument.class.name}") unless serializer
|
@@ -63,6 +66,7 @@ module ActiveJob
|
|
63
66
|
TimeWithZoneSerializer,
|
64
67
|
TimeSerializer,
|
65
68
|
ModuleSerializer,
|
66
|
-
RangeSerializer
|
69
|
+
RangeSerializer,
|
70
|
+
BigDecimalSerializer
|
67
71
|
end
|
68
72
|
end
|
@@ -34,7 +34,9 @@ module ActiveJob
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
ActiveSupport.on_load(:active_job) do
|
38
|
+
ActiveJob::Base.include(TestQueueAdapter)
|
39
|
+
end
|
38
40
|
|
39
41
|
def before_setup # :nodoc:
|
40
42
|
test_adapter = queue_adapter_for_test
|
@@ -54,15 +56,10 @@ module ActiveJob
|
|
54
56
|
queue_adapter_changed_jobs.each { |klass| klass.disable_test_adapter }
|
55
57
|
end
|
56
58
|
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# ActiveJob::QueueAdapters::TestAdapter.
|
61
|
-
#
|
62
|
-
# Note: The adapter provided by this method must provide some additional
|
63
|
-
# methods from those expected of a standard ActiveJob::QueueAdapter
|
64
|
-
# in order to be used with the active job test helpers. Refer to
|
65
|
-
# ActiveJob::QueueAdapters::TestAdapter.
|
59
|
+
# Returns a queue adapter instance to use with all Active Job test helpers.
|
60
|
+
# By default, returns an instance of ActiveJob::QueueAdapters::TestAdapter.
|
61
|
+
# Override this method to specify a different adapter. The adapter must
|
62
|
+
# implement the same interface as ActiveJob::QueueAdapters::TestAdapter.
|
66
63
|
def queue_adapter_for_test
|
67
64
|
ActiveJob::QueueAdapters::TestAdapter.new
|
68
65
|
end
|
@@ -354,6 +351,13 @@ module ActiveJob
|
|
354
351
|
# assert_enqueued_with(at: Date.tomorrow.noon, queue: "my_queue")
|
355
352
|
# end
|
356
353
|
#
|
354
|
+
# For keyword arguments, specify them as a hash inside an array:
|
355
|
+
#
|
356
|
+
# def test_assert_enqueued_with_keyword_arguments
|
357
|
+
# MyJob.perform_later(arg1: 'value1', arg2: 'value2')
|
358
|
+
# assert_enqueued_with(job: MyJob, args: [{ arg1: 'value1', arg2: 'value2' }])
|
359
|
+
# end
|
360
|
+
#
|
357
361
|
# The given arguments may also be specified as matcher procs that return a
|
358
362
|
# boolean value indicating whether a job's attribute meets certain criteria.
|
359
363
|
#
|
@@ -593,11 +597,17 @@ module ActiveJob
|
|
593
597
|
# assert_performed_jobs 1
|
594
598
|
# end
|
595
599
|
#
|
596
|
-
# If the +:at+ option is specified, then only
|
597
|
-
#
|
600
|
+
# If the +:at+ option is specified, then only jobs that have been enqueued
|
601
|
+
# to run at or before the given time will be performed. This includes jobs
|
602
|
+
# that have been enqueued without a time.
|
603
|
+
#
|
604
|
+
# If queue_adapter_for_test is overridden to return a different adapter,
|
605
|
+
# +perform_enqueued_jobs+ will merely execute the block.
|
598
606
|
def perform_enqueued_jobs(only: nil, except: nil, queue: nil, at: nil, &block)
|
599
607
|
return flush_enqueued_jobs(only: only, except: except, queue: queue, at: at) unless block_given?
|
600
608
|
|
609
|
+
return _assert_nothing_raised_or_warn("perform_enqueued_jobs", &block) unless using_test_adapter?
|
610
|
+
|
601
611
|
validate_option(only: only, except: except)
|
602
612
|
|
603
613
|
old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs
|
@@ -636,12 +646,16 @@ module ActiveJob
|
|
636
646
|
end
|
637
647
|
|
638
648
|
private
|
649
|
+
def using_test_adapter?
|
650
|
+
queue_adapter.is_a?(ActiveJob::QueueAdapters::TestAdapter)
|
651
|
+
end
|
652
|
+
|
639
653
|
def clear_enqueued_jobs
|
640
|
-
enqueued_jobs.clear
|
654
|
+
enqueued_jobs.clear if using_test_adapter?
|
641
655
|
end
|
642
656
|
|
643
657
|
def clear_performed_jobs
|
644
|
-
performed_jobs.clear
|
658
|
+
performed_jobs.clear if using_test_adapter?
|
645
659
|
end
|
646
660
|
|
647
661
|
def jobs_with(jobs, only: nil, except: nil, queue: nil, at: nil)
|
@@ -694,6 +708,10 @@ module ActiveJob
|
|
694
708
|
|
695
709
|
def prepare_args_for_assertion(args)
|
696
710
|
args.dup.tap do |arguments|
|
711
|
+
if arguments[:queue].is_a?(Symbol)
|
712
|
+
arguments[:queue] = arguments[:queue].to_s
|
713
|
+
end
|
714
|
+
|
697
715
|
if arguments[:at].acts_like?(:time)
|
698
716
|
at_range = arguments[:at] - 1..arguments[:at] + 1
|
699
717
|
arguments[:at] = ->(at) { at_range.cover?(at) }
|
data/lib/active_job/version.rb
CHANGED
data/lib/active_job.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c)
|
4
|
+
# Copyright (c) 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
|
@@ -26,16 +26,41 @@
|
|
26
26
|
require "active_support"
|
27
27
|
require "active_support/rails"
|
28
28
|
require "active_job/version"
|
29
|
+
require "active_job/deprecator"
|
29
30
|
require "global_id"
|
30
31
|
|
32
|
+
# :markup: markdown
|
33
|
+
# :include: ../README.md
|
31
34
|
module ActiveJob
|
32
35
|
extend ActiveSupport::Autoload
|
33
36
|
|
34
37
|
autoload :Base
|
35
38
|
autoload :QueueAdapters
|
36
|
-
autoload :
|
37
|
-
autoload :
|
39
|
+
autoload :Arguments
|
40
|
+
autoload :DeserializationError, "active_job/arguments"
|
41
|
+
autoload :SerializationError, "active_job/arguments"
|
42
|
+
|
43
|
+
eager_autoload do
|
44
|
+
autoload :Serializers
|
45
|
+
autoload :ConfiguredJob
|
46
|
+
end
|
47
|
+
|
38
48
|
autoload :TestCase
|
39
49
|
autoload :TestHelper
|
40
|
-
|
50
|
+
|
51
|
+
##
|
52
|
+
# :singleton-method:
|
53
|
+
# If false, \Rails will preserve the legacy serialization of BigDecimal job arguments as Strings.
|
54
|
+
# If true, \Rails will use the new BigDecimalSerializer to (de)serialize BigDecimal losslessly.
|
55
|
+
# Legacy serialization will be removed in \Rails 7.2, along with this config.
|
56
|
+
singleton_class.attr_accessor :use_big_decimal_serializer
|
57
|
+
self.use_big_decimal_serializer = false
|
58
|
+
|
59
|
+
##
|
60
|
+
# :singleton-method:
|
61
|
+
#
|
62
|
+
# Specifies if the methods calling background job enqueue should be logged below
|
63
|
+
# their relevant enqueue log lines. Defaults to false.
|
64
|
+
singleton_class.attr_accessor :verbose_enqueue_logs
|
65
|
+
self.verbose_enqueue_logs = false
|
41
66
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a new job. Pass the job name, either CamelCased or
|
3
|
+
under_scored, with or without the job postfix.
|
4
|
+
|
5
|
+
Examples:
|
6
|
+
`bin/rails generate job checkout`
|
7
|
+
|
8
|
+
Creates the following files:
|
9
|
+
|
10
|
+
Job: app/jobs/checkout_job.rb
|
11
|
+
Test: test/jobs/checkout_job_test.rb
|
12
|
+
|
13
|
+
`bin/rails generate job send_sms --queue=sms`
|
14
|
+
|
15
|
+
Creates a job and test with a custom sms queue.
|
16
|
+
|
17
|
+
`bin/rails generate job process_payment --parent=payment_job`
|
18
|
+
|
19
|
+
Creates a job and test with a `PaymentJob` parent class.
|
@@ -5,10 +5,10 @@ require "rails/generators/named_base"
|
|
5
5
|
module Rails # :nodoc:
|
6
6
|
module Generators # :nodoc:
|
7
7
|
class JobGenerator < Rails::Generators::NamedBase # :nodoc:
|
8
|
-
desc "This generator creates an active job file at app/jobs"
|
9
|
-
|
10
8
|
class_option :queue, type: :string, default: "default", desc: "The queue name for the generated job"
|
11
9
|
|
10
|
+
class_option :parent, type: :string, default: "ApplicationJob", desc: "The parent class for the generated job"
|
11
|
+
|
12
12
|
check_class_collision suffix: "Job"
|
13
13
|
|
14
14
|
hook_for :test_framework
|
@@ -28,6 +28,10 @@ module Rails # :nodoc:
|
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
|
+
def parent_class_name
|
32
|
+
options[:parent]
|
33
|
+
end
|
34
|
+
|
31
35
|
def file_name
|
32
36
|
@_file_name ||= super.sub(/_job\z/i, "")
|
33
37
|
end
|