配置/ 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 with gem来安排Rails中的作业。以上是我的日程表.rb。是否有办法以比上述更好的方式安排任务? (例如时间+ 1.分钟或时间+2分钟)
如果有任何更好的方法来调度上述任务将会有所帮助。
选项1:
因为这是一个Ruby代码,所以您可以动态地迭代应用程序,任务和动态设置调度程序的数组
选项2:你实际上可以做每一分钟:跑步者'AppTaskRunner.perform_async'结束
而在AppTaskRunner中,每个应用程序启动所需的任务取决于您的逻辑