Whenever cron job is not working in rails 3

▼魔方 西西 提交于 2019-12-01 05:54:58

问题


This is the code in my schedule file. I am using 1 min just to test whether its working or not.

every 1.minutes do
  runner "User.update_all('daily_sms_count' = 0 )"
end

from terminal i setup

whenever --set environment=development --update-crontab 1mintesting

Whats the issue?


回答1:


Are you using RVM? If so, Whenever generates a crontab entry like this:

* * * * * /bin/bash -l -c 
'cd /Users/myuser/Documents/Projects/foo && script/rails runner -e 
development '\''User.update_all("daily_sms_count" = 0 )'\'''

This means that it won't necessarily be using your project's version of Ruby and associated gemset as it spins off a new bash shell. To make this work, you need to add an appropriate .rvmrc file to your project's root folder. This way, the cd /Users/myuser/Documents/Projects/foo part of the generated crontab entry will ensure that the appropriate RVM settings are used. Just make sure that when you add the .rvmrc file, cd.. and back into the project to make RVM recognize your project's .rvmrc.

If you are not using RVM, run crontab -l, and copy the generated entry, and run it from terminal to see if it runs with no errors or not.

If you are using Mac, cron will send log messages to your mailbox and you can view them using the mail command.

If these tricks didn't work, give me more details about your working environment (OS, RVM, etc.) so that I can help you more.



来源:https://stackoverflow.com/questions/6980720/whenever-cron-job-is-not-working-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!