我在schedule.rb
一個任務:我該如何創建相同的cron作業,以便隨時隨地創建作品?
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作業爲同一臺服務器上的兩個單獨的環境?