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.

THpubs
  • 7,804
  • 16
  • 68
  • 143
  • just check the crontab? also/or try reading the docs/source – mmln May 17 '15 at 14:32
  • That will probably be the easiest. The hardest part of that might be interpreting the arcane crontab syntax, but [there are tools](http://www.cronchecker.net/) for that – 3Doubloons May 17 '15 at 14:35

1 Answers1

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.

Community
  • 1
  • 1
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74