每当 gem 并从偏移量开始每 n 分钟安排一次作业
出于惊人的目的,我尝试将作业安排为每 5 分钟运行一次 2 分钟的偏移量。也就是说,我希望 1 个作业运行 1,6,11,16..,另一个作业运行在 2,7,12,17...
我找不到执行此操作的示例。所以我尝试了:
every 5.minutes, :at=> 1 do
command "echo 'you can use raw cron sytax too'"
end
这似乎可行,但所有 ':at' 示例看起来都期待字符串格式的时间。上述操作是否有效,或者只是碰巧起作用,并且每个选项并不真正支持开始时间。
For staggering purposes I am trying to schedule jobs an a 2 minute offset that run every 5 mins. That is I want 1 job to run 1,6,11,16.. and the other one to run at 2,7,12,17...
I couldn't find an example to do this. So I tried:
every 5.minutes, :at=> 1 do
command "echo 'you can use raw cron sytax too'"
end
This seems to work but all the ':at' examples look to be expecting a time in a string format. Is the above valid to do or is just happens to work and the every option doesn't really support a starting time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来这两项工作之间存在依赖关系,所以我认为您可以通过两种方法来处理这个问题。如果您想在 1,6,11,16 等运行,正如您的问题所示,那么只需使用原始 cron 语法:
但最好在第一个作业完成后执行第二个作业。这应该确保作业不会重叠,并且第二个作业仅在第一个作业完成后运行。
It sounds like you have a dependency between the two jobs, so there are two ways I think you can handle this. If you want to run at 1,6,11,16 and so on, as your question suggests, then simply use raw cron syntax:
But it's probably better to execute the second job once the first one is done. This should ensure that the jobs don't overlap and that the second only runs when after the first completes.
every
需要一个整数。为了避免雷群问题,你可以这样做。
您也可以随机化偏移量,
就像其他答案一样,这不适用于相互依赖的任务。如果您的任务相互依赖,您应该使用
rake
来为您处理它,或者在您的任务中手动运行下一个任务。every
expects an integer.To avoid thundering herd problem, you can do this.
You can randomise the offset too
Like other answers this won't work for tasks depending on each other. If your tasks depend on each other, you should use
rake
to handle it for you or run next one manually in your task.是的,这应该是有效的。看看 https://github.com/javan/whenever/blob /master/lib/whenever/cron.rb
看一下parse_time方法。这些行特别是:
Yes, that should be valid. Look at https://github.com/javan/whenever/blob/master/lib/whenever/cron.rb
Look at the parse_time method. These lines in particular: