I have an application that contains a bunch of tasks, and every day I want to run a cron job that creates a DayTask for each Task in the database. A Task has_many DayTasks a
Finally I have solved how to run the gem Whenever. It's working good on production, but not in development mode (I think that to working good in dev mode you must do some tricks).
Then, these are the processes to do:
scheduler.rb
filessh
)whenever
whenever --update-crontab
sudo service cron restart
crontab -l
That's it!
Personally, I prefer to set up my crons directly from the server:
crontab -e
0 5 * * * /bin/bash -l -c 'cd /path_to_my_app/current && RAILS_ENV=production bundle exec rake my_cron_rake'
crontab -l
Try to execute the whenever generated command directly from terminal or add the following line
MAILTO=your@emailadress.com
to your crontab.
You have to actually register the job with the crontab by running:
whenever --update-crontab
Also if you're trying to get jobs running locally, add
:environment => "development"
to your task
runner "MyTask.some_action", :environment => "development"
if whenever
command gives you -bash: whenever: command not found
, try bundle exec whenever