在每当 gem 中,如果我们每个 :month 都使用,它是指月末还是月初? [英] In Whenever gem, if we use every :month, does it mean the end of month or beginning?
问题描述
当使用 whenever
gem 时,我们可以像这样设置每月工作:
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.
推荐答案
来自 每当 repo 中的测试:
assert_equal '0 0 1 * *', parse_time(:month)
所以 :month
将生成一个看起来像 0 0 1 * *..
So :month
will generate a cron entry that looks like 0 0 1 * *..
这对应于每月第一天午夜运行一次.
让作业在每月最后一天运行的一种方法是在任何地方使用原始 cron 条目,如下所示:
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
这里假设服务器上的 cron 支持 L
标志来表示一个月的最后一天.
This assumes that the cron on the server supports the L
flag for representing the last day of the month.
请参阅 Cron 作业以在每月的最后一天,了解有关在该月的最后一天运行 Cron 作业的更多信息.
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.
这篇关于在每当 gem 中,如果我们每个 :month 都使用,它是指月末还是月初?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!