Help with the "Whenever" gem in Ruby for cron tasks
Asked Answered
L

1

5

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.

Lemuroid answered 13/10, 2010 at 21:25 Comment(0)
I
12

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
Idalia answered 13/12, 2010 at 18:4 Comment(1)
Note that whenever -i is a little safer than whenever -w, which will overwrite your entire crontab. The former only updates the entries in crontab related to whenever, leaving any other entries untouched. You can always verify that your crontab has been updated correctly by running crontab -l.Skunk

© 2022 - 2024 — McMap. All rights reserved.