config / schedule.rb
def timezoned time
Time.zone = "Pacific Time (US & Canada)"
Time.zone.parse(time).utc
end
every 1.day, at: timezoned('5:30 am') do
runner 'App1::Task1.perform_async'
end
every 1.day, at: timezoned('5:31 am') do
runner 'App1::Task2.perform_async'
end
every 1.day, at: timezoned('5:33 am') do
runner 'App2::Task1.perform_async'
end
every 1.day, at: timezoned('5:34 am') do
runner 'App2::Task2.perform_async'
end
every 1.day, at: timezoned('5:36 am') do
runner 'App3::Task1.perform_async'
end
every 1.day, at: timezoned('5:37 am') do
runner 'App3::Task2.perform_async'
end
every 1.day, at: timezoned('5:40 am') do
runner 'App4::Task1.perform_async'
end
every 1.day, at: timezoned('5:41 am') do
runner 'App4::Task2.perform_async'
end
every 1.day, at: timezoned('5:42 am') do
runner 'App4::Task3.perform_async'
end
every 1.day, at: timezoned('5:43 am') do
runner 'App5::Task4.perform_async'
end
我将Sidekiq与gem一起使用,以计划Rails中的作业。 以上是我的schedule.rb。有没有比上面更好的方式安排任务的方法? (例如,时间+ 1.分钟或时间+ 2.分钟)
如果有比上述更好的计划任务的方法,将会很有帮助。
答案 0 :(得分:0)
选项1:
由于这是Ruby代码,因此您可以动态遍历一系列应用程序,任务并动态设置计划程序
选项2: 你实际上可以 每分钟 跑步者'AppTaskRunner.perform_async' 结束
在AppTaskRunner中,启动每个应用所需的任务取决于您的逻辑