Skip to content

Commit f70cca1

Browse files
committed
Accept a block for ActiveJob::ConfiguredJob#perform_later
1 parent 31c060c commit f70cca1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

activejob/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Accept a block for `ActiveJob::ConfiguredJob#perform_later`.
2+
3+
This was inconsistent with a regular `ActiveJob::Base#perform_later`.
4+
5+
*fatkodima*
6+
17
* Raise a more specific error during deserialization when a previously serialized job class is now unknown.
28

39
`ActiveJob::UnknownJobClassError` will be raised instead of a more generic

activejob/lib/active_job/configured_job.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ def perform_now(...)
1212
end
1313

1414
def perform_later(...)
15-
@job_class.new(...).enqueue @options
15+
job = @job_class.new(...)
16+
enqueue_result = job.enqueue(@options)
17+
18+
yield job if block_given?
19+
20+
enqueue_result
1621
end
1722

1823
def perform_all_later(multi_args)

activejob/test/cases/queuing_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ class QueuingTest < ActiveSupport::TestCase
5050
end
5151
end
5252

53+
test "configured job is yielded to block after enqueue with successfully_enqueued property set" do
54+
HelloJob.set(queue: :some_queue).perform_later "John" do |job|
55+
assert_equal "John says hello", JobBuffer.last_value
56+
assert_equal [ "John" ], job.arguments
57+
assert_equal "some_queue", job.queue_name
58+
assert_equal true, job.successfully_enqueued?
59+
end
60+
end
61+
5362
test "when enqueuing raises an EnqueueError job is yielded to block with error set on job" do
5463
EnqueueErrorJob.perform_later do |job|
5564
assert_equal false, job.successfully_enqueued?

0 commit comments

Comments
 (0)