【发布时间】:2011-10-02 19:50:46
【问题描述】:
我在schedule.rb有一份工作:
set :output, File.expand_path('../log/whenever.log', __FILE__)
set :job_template, "bash -l -c 'source ~/.bashrc ; :job'"
every 1.day, :at => '12:01 am' do
runner "MyModel.do_something"
end
在我的暂存部署 (bash) 脚本中,我将这一行写入 cron:
ssh $SERVER "cd $DEPLOY_TO && whenever --set environment=staging -w"
生产部署脚本中的这一行:
ssh $SERVER "cd $DEPLOY_TO && whenever --set environment=production -w"
这可以正常工作,并在我部署任一环境时创建工作。问题是,每当将它们都视为一项工作时,它就会被上次部署的环境覆盖:
# Begin Whenever generated tasks for: /Users/simon/apps/myapp/staging/config/schedule.rb
1 0 * * * bash -l -c 'source ~/.bashrc ; cd /Users/simon/apps/myapp/staging && script/rails runner -e staging 'MyModel.do_something' >> /Users/simon/apps/myapp/staging/log/whenever.log 2>&1'
# End Whenever generated tasks for: /Users/simon/apps/myapp/staging/config/schedule.rb
还有……
# Begin Whenever generated tasks for: /Users/simon/apps/myapp/production/config/schedule.rb
1 0 * * * bash -l -c 'source ~/.bashrc ; cd /Users/simon/apps/myapp/production && script/rails runner -e production 'MyModel.do_something' >> /Users/simon/apps/myapp/production/log/whenever.log 2>&1'
# End Whenever generated tasks for: /Users/simon/apps/myapp/production/config/schedule.rb
在同一台服务器上为两个不同的环境添加相同的 cron 作业的明智方法是什么?
【问题讨论】:
标签: ruby-on-rails ruby whenever