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

1

5

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.

Bilbe answered 17/5, 2015 at 14:23 Comment(2)
just check the crontab? also/or try reading the docs/sourceDeanndeanna
That will probably be the easiest. The hardest part of that might be interpreting the arcane crontab syntax, but there are tools for thatErik
B
8

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.

Blanc answered 17/5, 2015 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.