monthly jobs syntax question

153 views
Skip to first unread message

Scott Miller

unread,
Jul 23, 2009, 12:09:21 PM7/23/09
to Whenever Gem
First of all, I want to thank you for the awesomeness that is
whenever. I did have a question about using it though for monthly
cron jobs:

We have a couple rake tasks that need to run monthly, at a certain
time, and (possibly) on a certain day. So would that be specified
with something like:

every 1.month, :at => '3am' do
something_cool
end

Would this run on the 1st of the month, at 3am?

What if it needed to run on the 5th of the month at 3am?

Scott

Javan Makhmali

unread,
Jul 23, 2009, 12:35:59 PM7/23/09
to whenev...@googlegroups.com
Hey Scott, the 1.month jobs are a little ugly, but doable.

Because Whenever uses Chronic to parse times, "3am" would mean 3am
today which would mean your cron jobs would run on whatever date today
was.

The trick is to do something like:

every 1.month, :at => "January 5th at 3am"

That way whenever knows what day you're talking about. I haven't
figured out a way to get the "January" out of there, but I can assure
you the job will run every month.

One slightly better syntax if you want the job to run on the 1st is to
say "beginning of the month at 3am".

Javan

Scott Miller

unread,
Jul 23, 2009, 1:10:16 PM7/23/09
to Whenever Gem
Hey cool thanks for this. That makes sense. I think we'll stick to
the beginning of the month because that avoids the end of month
problem (28th, 29th, 30th, 31st are not present in every month.) Not
sure how Chronic handles those cases...

So the recommended approach is

every 1.month, :at => "beginning of the month at 3am"
Reply all
Reply to author
Forward
0 new messages