如何在 Active Job (Rails 4.2) 中安排重复作业? [英] How do I schedule recurring jobs in Active Job (Rails 4.2)?
本文介绍了如何在 Active Job (Rails 4.2) 中安排重复作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了这个在 Rails 中安排一次性工作但这仅显示如何安排一次.我对安排定期工作感兴趣.
I found this Schedule one-time jobs in Rails but this only shows how schedule one-time. I am interested in scheduling a recurring job.
Delayed_job 有这个
Delayed_job has this
self.delay(:run_at => 1.minute.from_now)
如何在 Rails 4.2/Active Job 中做类似的事情?
How do I do something like that in Rails 4.2/Active Job?
推荐答案
类似于 rab3 的回答,由于 ActiveJob 支持回调,我正在考虑做类似的事情
Similar to rab3's answer, since ActiveJob has support for callbacks, I was thinking of doing something like
class MyJob < ActiveJob::Base
after_perform do |job|
# invoke another job at your time of choice
self.class.set(:wait => 10.minutes).perform_later(job.arguments.first)
end
def perform(the_argument)
# do your thing
end
end
这篇关于如何在 Active Job (Rails 4.2) 中安排重复作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文