用于 ActiveJob::Continuable 作业的测试助手。
方法
包含的模块
实例公共方法
interrupt_job_after_step(job, step, &block) 链接
在某个步骤后 中断 作业。
请注意,最后一个步骤之后没有检查点,因此不会被中断。
class MyJob < ApplicationJob
include ActiveJob::Continuable
cattr_accessor :items, default: []
def perform
step :step_one { items << 1 }
step :step_two { items << 2 }
step :step_three { items << 3 }
step :step_four { items << 4 }
end
end
test "interrupt job after step" do
MyJob.perform_later
interrupt_job_after_step(MyJob, :step_two) { perform_enqueued_jobs }
assert_equal [1, 2], MyJob.items
perform_enqueued_jobs
assert_equal [1, 2, 3, 4], MyJob.items
end
来源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/continuation/test_helper.rb, line 65 def interrupt_job_after_step(job, step, &block) require_active_job_test_adapter!("interrupt_job_after_step") queue_adapter.with(stopping: ->() { after_step?(job, step) }, &block) end
interrupt_job_during_step(job, step, cursor: nil, &block) 链接
在某个步骤 期间中断 作业。
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
来源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/continuation/test_helper.rb, line 36 def interrupt_job_during_step(job, step, cursor: nil, &block) require_active_job_test_adapter!("interrupt_job_during_step") queue_adapter.with(stopping: ->() { during_step?(job, step, cursor: cursor) }, &block) end