我已按如下方式设置我的 schedule.rb 文件。
set :cron_log, "/log/cron_log.log"
if Rails.env.development?
every 1.minute do
runner "SomeModel.move_values"
runner "SomeOtherModel.dispense"
end
end
我也让它在开发模式下工作 每当 --update-crontab trunk --set environment=development
但是我的模型方法(类方法)从未被调用过。有什么方法可以验证它的配置是否正确。 当我简单地使用更新时,它会重置设置以使用生产环境。
最佳答案
我刚刚使用相同的 javan-whenever 插件。
在终端中,输入 crontab -l
。
如果您看到正确生成的 crontab,那么您就知道它要么是代码,要么是某些服务器的东西。
您可能需要考虑在 schedule.rb 文件中执行 set :environment, RAILS_ENV
以动态设置环境。
Ryan Bates 对此进行了很好的截屏: http://railscasts.com/episodes/164-cron-in-ruby
此外,还有基于网络的替代方案,例如: webbasedcron
关于ruby-on-rails - 在 Rails 中使用 Javan-whenever 时如何让 cron 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1715094/