【发布时间】:2010-11-07 09:36:26
【问题描述】:
这个问题可能只有在您了解创建 cron 作业的whengem 时才有意义。我的 schedule.rb 中有一个任务,例如
every 1.day, :at => '4am' do
command "cd #{RAILS_ROOT} && rake thinking_sphinx:stop RAILS_ENV=#{RAILS_ENV}"
command "cd #{RAILS_ROOT} && rake thinking_sphinx:index RAILS_ENV=#{RAILS_ENV}"
command "cd #{RAILS_ROOT} && rake thinking_sphinx:start RAILS_ENV=#{RAILS_ENV}"
end
但是当我使用更新我的 crontab 时
whenever --update-crontab appname --set environment=production
cron 作业仍然有 RAILS_ENV=development。我现在的生产和开发任务是一样的,我只需要改变环境变量,因为thinking_sphinx需要知道当前的环境。关于如何做到这一点的任何想法?
谢谢!
【问题讨论】:
-
在我的特殊情况下(开始延迟作业)我使用
command "RAILS_ENV=#{@environment} #{Whenever.path}/bin/delayed_job start"得到了这个工作 -
如果您运行 rake,您还可以在
whenever上下文中使用rake命令。
标签: ruby-on-rails cron whenever