wwli
wwli

Reputation: 2681

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

Upvotes: 0

Views: 3243

Answers (1)

glast
glast

Reputation: 383

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.

Upvotes: 4

Related Questions