In Whenever gem, if we use every :month, does it mean the end of month or beginning?

ε祈祈猫儿з 提交于 2021-02-07 09:45:48

问题


When using the whenever gem we can set a monthly job like this :

every :month do
    ...
end

Will this run the job at the end of the month or at the start of the month? I want to run it at the end.


回答1:


From the tests in whenever repo:

assert_equal '0 0 1 * *',  parse_time(:month)

So :month will generate a cron entry that looks like 0 0 1 * *..

This corresponds to run once a month at midnight of the first day of the month.

One way to make the job run last day of the month would be to use the raw cron entry in wherever as follows:

every '0 0 L * *' do
  ...
end

This assumes that the cron on the server supports the L flag for representing the last day of the month.

See Cron job to run on the last day of the month for more about running a cron job on the last day of the month.



来源:https://stackoverflow.com/questions/30287818/in-whenever-gem-if-we-use-every-month-does-it-mean-the-end-of-month-or-beginn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!