ruby-on-railscronwhenever

Rails: Scheduled Job not Running


I'm using the Whenever gem with my Rails 3.2 app on an Ubuntu server. I have a monthly job that I want to run on the first day of the month, but it didn't seem to work.

I know that the code works because I ran it from the console on the server when I found it didn't run. I have other jobs that run more frequently (hourly, daily), but this one didn't run. Can someone please help me determine what I did wrong?

# schedule.rb
every 1.month, :at => "beginning of the month at 3am" do
  rake "users:update_monthly"
end

# lib/schedule.rake
namespace :users do

  task :update_monthly => :environment do
    User.update_monthly
  end

end

When I run crontab -l on the server:

# Begin Whenever generated tasks for: whenever_schedule
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/articles

0 3 1 * * /bin/bash -l -c 'cd /var/deploy/foo/web_head/releases/20130801200106 && RAILS_ENV=production bundle exec rake users:update_monthly --silent'

# End Whenever generated tasks for: whenever_schedule

Solution

  • It looks like this is a Chronic parsing issue.

    This might work:

    every 1.month, :at => 'January 1st 3:00am' do
      rake "users:update_monthly"
    end
    

    Or this:

    every 1.month, :at => 'start of the month at 9am' do
      rake "users:update_monthly"
    end
    

    It is tough because it looks like the crontab output on the server looks right.