例如,我有一份工作,我希望每 1 小时重复一次。这是我的代码:
class NewsletterJob < ApplicationJob
queue_as :default
after_perform do |job|
NewsletterJob.set(wait: 1.hour).perform_later user
end
def perform(*args)
puts "I am busy mailing newsletter."
end
end
我的问题是:如何调用满足两个条件的上述代码:
- 服务器启动时自动运行。
- 只运行一次。例如,我使用 sidekiq 作为消息队列。所以我希望下次重启服务器时,只有一个作业实例可用。
最佳答案
关于ruby-on-rails - 事件作业 : start a job automatically when starting server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42818099/