每当 cron 作业在 Rails 3 中不起作用时 [英] Whenever cron job is not working in rails 3

查看:60
本文介绍了每当 cron 作业在 Rails 3 中不起作用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的计划文件中的代码.我用 1 分钟只是为了测试它是否工作.

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

从我设置的终端

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

有什么问题吗?

推荐答案

您在使用 RVM 吗?如果是这样,每当生成这样的 crontab 条目:

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 )'\'''

这意味着它不一定会使用您项目的 Ruby 版本和相关的 gemset,因为它会衍生出一个新的 bash shell.要使此工作正常运行,您需要将适当的 .rvmrc 文件添加到项目的根文件夹中.这样,生成的 crontab 条目的 cd/Users/myuser/Documents/Projects/foo 部分将确保使用适当的 RVM 设置.只需确保在添加 .rvmrc 文件时,cd.. 并返回到项目中,以使 RVM 识别您项目的 .rvmrc.

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.

如果您没有使用 RVM,请运行 crontab -l,并复制生成的条目,然后从终端运行它,看看它是否运行没有错误.

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.

如果您使用的是 Mac,cron 会将日志消息发送到您的邮箱,您可以使用 mail 命令查看它们.

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

如果这些技巧不起作用,请提供有关您的工作环境(操作系统、RVM 等)的更多详细信息,以便我可以为您提供更多帮助.

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

这篇关于每当 cron 作业在 Rails 3 中不起作用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆