我有一份工作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 作业的明智方法是什么?