开发者

Cron job scheduled, but not running rake task

I'm struggling trying to make a cron job run. Here is what I have:

开发者_StackOverflow社区
*/1 * * * * cd /home/jose/work/Cronox/lib/tasks/rake wines:destroy_wines >> /home/jose/crontab_errors.txt

My task looks like this:

namespace :wines do
  desc "delete all wines"
  task :destroy_wines => :environment do |t|
    Wine.delete_all!
  end
end

If I use this command: tail -f /var/log/syslog I can see this:

(jose) CMD (cd /home/jose/work/Cronox/lib/tasks/rake wines:destroy_wines >> /home/jose/crontab_errors.txt)

Every minute, But it does nothing at all. I'm also using rvm Does that have anything to do with it?

One more thing: when executed manually the task works fine.

What am I missing,

please, please help me !


I used something similar to Jeff's answer, but I had to invoke bundle exec to get the rake task to run properly, and to do that I had to use the rvm do command. Full cronjob looks like this:

*/15 * * * * cd /path/to/rails/app && /path/to/rvm 1.9.3-p392 do bundle exec rake RAILS_ENV=production my:rake:task >> tasks.log 2>&1


I have created an example and this is the command line:

 /bin/bash -l -c 'cd /home/myusername/rails_apps/yourapplicationname && RAILS_ENV=production bundle exec rake admin:update_folios --trace --silent >> log/error_updating_folios.log'

You can find the full guide here:

http://heridev.com.mx/ruby/how-to-create-a-cron-job-for-ruby-on-rails-application-in-a-server-wich-uses-cpanel/

Cheers!


You aren't invoking rake, you're just changing to the directory. Try

*/1 * * * * cd /home/jose/work/Cronox/ && rake wines:destroy_wines >> /home/jose/crontab_errors.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜