简体   繁体   English

如何使用Rufus Scheduler安排日常工作

[英]How to schedule daily job using Rufus Scheduler

I am trying to schedule a daily job using Rufus Scheduler. 我正在尝试使用Rufus Scheduler安排日常工作。 Is this a correct way doing it? 这是正确的方法吗?

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

scheduler.every '1d' do
  # Daily job code
end

Or should I create a cron job ? 还是我应该创建一个cron作业? Cannot find anything in Rufus documentation. 在Rufus文档中找不到任何内容。

Is this a correct way doing it ? 这是正确的方法吗?

Yes, it is a correct way of doing it. 是的,这是正确的方法。

Or should I create a cron job ? 还是我应该创建一个cron作业?

It depends on what you are building. 这取决于您要构建的内容。

Doing 在做

scheduler.every '1d' do
  # ...
end

will schedule now and then again in now + 24 * 3600 seconds and then again in now + 2 * 24 * 3600 seconds... 将立即排定现在+ 24 * 3600秒,然后立即排定+ 2 * 24 * 3600秒...

Doing 在做

scheduler.cron '0 2 * * *' do
  # ...
end

will schedule every day at 2am. 将每天安排在凌晨2点。

Some people prefer the certainty of having some admin jobs run while the system is less busy (hence my example choice of 2am). 有些人希望在系统不那么忙时可以运行一些管理作业的确定性(因此我选择凌晨2点)。

The rufus-scheduler documentation is explaining both and trusting you to choose the one that fits your requirements. rufus-scheduler文档正在对这两者进行解释,并相信您可以选择适合您要求的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM