简体   繁体   中英

rails : running rake task in cron job

I am trying to run rake task in cron job like this

0 * * * *  cd /var/www/rails_path/rails && rake my_task RAILS_ENV=production

I can run this command

cd /var/www/rails_path/rails && rake my_task RAILS_ENV=production

from shell and got result.

And I checked the cron log the commond did get run. But in fact the rake task didn't get run when the cron job excutes (the task should have logs, I didn't see logs of this rake task after cron job ran).

What is the issue?

UPDATED:

tried

0 * * * * /bin/bash -l -c "cd /var/www/rails_path/rails && rake my_task RAILS_ENV=production"

no luck

installed whenever gem and have

every 2.minutes do
   rake "my_task"
end

in ./config/schdule.rb. It was not running at all (I deployed rails in nginx with passenger).

Thanks

Try this:

0 * * * * /bin/bash -l -c 'cd your_app_path && RAILS_ENV=production bundle exec rake your_task'

Or, it is good to use whenever gem if you want to do command line rails work in cron.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM