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:
- sudo gem install whenever
- change to the application directory
- wheneverize . (this created the file schedule.rb)
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
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
I did this in the terminal: whenever
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开发者_开发技巧'
Running these commands individually in the terminal works:
script/runner -e development 'Digest.rss' script/runner -e development 'User.vote'
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.
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
精彩评论