Rails cron with whenever, setting the environment
cron, ruby-on-rails, whenever
Solution
I would consider using the "rake" shortcut to make it even cleaner:
every 1.day, :at => '4am' do
rake "thinking_sphinx:stop"
rake "thinking_sphinx:index"
rake "thinking_sphinx:start"
end
Problem
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 => '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 ``` However when I update my crontab using ``` whenever --update-crontab appname --set environment=production ``` the cron jobs still have RAILS_ENV=development. My tasks on production and development are the same right now, I just need to change the environment variable because thinking_sphinx needs to know the current environment. Any ideas on how to do this? Thanks!