instance method
interrupt_job_during_step
Ruby on Rails edge
Since v8.1.3.1Available in: v8.1.3.1 edge
Signature
interrupt_job_during_step(job_class, step, cursor: nil, reason: true, &block)
Interrupt a job during a step.
class MyJob < ApplicationJob
include ActiveJob::Continuable
cattr_accessor :items, default: []
def perform
step :my_step, start: 1 do |step|
(step.cursor..10).each do |i|
items << i
step.advance!
end
end
end
end
test "interrupt job during step" do
MyJob.perform_later
interrupt_job_during_step(MyJob, :my_step, cursor: 6) { perform_enqueued_jobs }
assert_equal [1, 2, 3, 4, 5], MyJob.items
perform_enqueued_jobs
assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], MyJob.items
end
A custom interrupt reason can be provided with the reason argument.
Parameters
-
job_classreq -
stepreq -
cursorkey = nil -
reasonkey = true -
blockblock
Source
# File activejob/lib/active_job/continuation/test_helper.rb, line 38
def interrupt_job_during_step(job_class, step, cursor: nil, reason: true, &block)
require_active_job_test_adapter!("interrupt_job_during_step")
stopping = ->(job) { reason if job.is_a?(job_class) && during_step?(job, step, cursor: cursor) }
queue_adapter.with(stopping: stopping, &block)
end
Defined in activejob/lib/active_job/continuation/test_helper.rb line 38
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveJob::Continuation::TestHelper