Rails cron with whenever, setting the environment

前端 未结 10 2108
孤街浪徒
孤街浪徒 2021-01-30 13:15

This question will probably only make sense if you know about the whenever gem for creating cron jobs. I have a task in my schedule.rb like

every 1.day, :at =&g         


        
10条回答
  •  爱一瞬间的悲伤
    2021-01-30 14:06

    Don't write the RAILS_ENV variable. It should set it automatically.

    every 1.day, :at => '4am' do
      command "cd #{RAILS_ROOT} && rake thinking_sphinx:stop"
      command "cd #{RAILS_ROOT} && rake thinking_sphinx:index"
      command "cd #{RAILS_ROOT} && rake thinking_sphinx:start"
    end
    

    It works in my app:

    every 4.days do
      runner "AnotherModel.prune_old_records"
    end
    
    $ whenever --set environment=production
    0 0 1,5,9,13,17,21,25,29 * * /Users/weppos/Sites/git/app/script/runner -e production "AnotherModel.prune_old_records"
    
    $ whenever --set environment=development
    0 0 1,5,9,13,17,21,25,29 * * /Users/weppos/Sites/git/app/script/runner -e development "AnotherModel.prune_old_records"
    

提交回复
热议问题