提供在异常情况下重试和丢弃作业的行为。
命名空间
方法
实例公共方法
retry_job(options = {}) 链接
重新安排作业以重新执行。这与 rescue_from 结合使用时非常有用。当您从作业中拯救异常时,您可以要求 Active Job 重试执行您的作业。
选项
-
:wait
- 以指定的延迟(以秒为单位)加入作业 -
:wait_until
- 在指定的时间加入作业 -
:queue
- 在指定的队列中加入作业 -
:priority
- 以指定的优先级加入作业
示例
class SiteScraperJob < ActiveJob::Base
rescue_from(ErrorLoadingSite) do
retry_job queue: :low_priority
end
def perform(*args)
# raise ErrorLoadingSite if cannot scrape
end
end
源代码:显示 | 在 GitHub 上
# File activejob/lib/active_job/exceptions.rb, line 157 def retry_job(options = {}) instrument :enqueue_retry, options.slice(:error, :wait) do enqueue options end end