mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
AJ perform_enqueued_jobs
shouldn't perform job retries:
- ### Problem If we use `perform_enqueued_jobs` without a block, a job that uses a retry mechanism to reeenqueue itself would get performed right away. This behaviour make sense when using `perform_enqueued_jobs` with a block. However I'm expecting `perform_enqueued_jobs` without a block to perform jobs that are **already** in the queue not the ones that will get enqueued afterwards. ### Solution Dup the array of jobs given to avoid future mutation.
This commit is contained in:
parent
13cb5b78a8
commit
17e304def8
3 changed files with 27 additions and 6 deletions
|
@ -1,3 +1,13 @@
|
|||
* `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries:
|
||||
|
||||
When calling `perform_enqueued_jobs` without a block, the adapter will
|
||||
now perform jobs that are **already** in the queue. Jobs that will end up in
|
||||
the queue afterwards won't be performed.
|
||||
|
||||
This change only affects `perform_enqueued_jobs` when no block is given.
|
||||
|
||||
*Edouard Chin*
|
||||
|
||||
* Add queue name support to Que adapter
|
||||
|
||||
*Brad Nauta*, *Wojciech Wnętrzak*
|
||||
|
|
|
@ -602,7 +602,7 @@ module ActiveJob
|
|||
def jobs_with(jobs, only: nil, except: nil, queue: nil, at: nil)
|
||||
validate_option(only: only, except: except)
|
||||
|
||||
jobs.count do |job|
|
||||
jobs.dup.count do |job|
|
||||
job_class = job.fetch(:job)
|
||||
|
||||
if only
|
||||
|
|
|
@ -919,6 +919,17 @@ class PerformedJobsTest < ActiveJob::TestCase
|
|||
assert_equal(1, performed_jobs.size)
|
||||
end
|
||||
|
||||
def test_perform_enqueued_jobs_dont_perform_retries
|
||||
RaisingJob.perform_later
|
||||
|
||||
assert_nothing_raised do
|
||||
perform_enqueued_jobs(only: RaisingJob)
|
||||
end
|
||||
|
||||
assert_equal(1, performed_jobs.size)
|
||||
assert_equal(2, enqueued_jobs.size)
|
||||
end
|
||||
|
||||
def test_assert_performed_jobs
|
||||
assert_nothing_raised do
|
||||
assert_performed_jobs 1 do
|
||||
|
@ -1877,13 +1888,13 @@ class PerformedJobsTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
test "TestAdapter respect max attempts" do
|
||||
RaisingJob.perform_later
|
||||
|
||||
perform_enqueued_jobs(only: RaisingJob) do
|
||||
assert_raises(RaisingJob::MyError) do
|
||||
perform_enqueued_jobs
|
||||
RaisingJob.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 2, queue_adapter.enqueued_jobs.count
|
||||
assert_equal 2, queue_adapter.performed_jobs.count
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue