Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with the "Whenever" gem in Ruby for cron tasks

I have not used cron before, so I can't be sure that I did this right. The tasks I want to be automated don't seem to be running. I did these steps in the terminal:

  1. sudo gem install whenever
  2. change to the application directory
  3. wheneverize . (this created the file schedule.rb)
  4. I added this code to schedule.rb:

    every 10.minutes do
      runner "User.vote", environment => "development"
    end
    
    
    every :hour do
      runner "Digest.rss", :environment => "development"
    end
    
  5. I added this code to deploy.rb:

    after "deploy:symlink", "deploy:update_crontab"
    
    
    namespace :deploy do
      desc "Update the crontab file"
      task :update_crontab, :roles => :db do
        run "cd #{current_path} && whenever --update-crontab #{application}"
      end
    end
    
  6. I did this in the terminal: whenever

  7. It returned:

    @hourly cd /Users/RedApple/S && script/runner -e development 'Digest.rss'
    
    
    0,10,20,30,40,50 * * * * cd /Users/RedApple/S && script/runner -e development 'User.vote'
    
  8. Running these commands individually in the terminal works:

    script/runner -e development 'Digest.rss'
    script/runner -e development 'User.vote'
    
  9. Now running a local server in development mode, script/server, I don't see any evidence that the code is actually being run. Is there some step that I didn't do? No guides for "Whenever" show anything else than what I have done.

like image 469
Eric Avatar asked Oct 13 '10 21:10

Eric


1 Answers

I'm new to whenever as well, but i think that just running

whenever

just shows you what the cron job that is created will look like. In order to actually write the cron job (to make it active), you need to execute:

whenever -w

This will get you a full list of options:

whenever -h
like image 76
ilasno Avatar answered Sep 21 '22 20:09

ilasno