Following situation:
I have a server and some rake tasks which should run the whole time, f.e.:
# email_sender.rake (except only)
while true
fetch all mail entries.each do |mail|
mail.deliver
end
end
or another rake task
# update_market.rake (except only)
while true
Market.fetch_exchange_rate!
sleep 1
end
For starting and stopping these rake tasks i use the god gem and it works quite well.
But one thing isn’t clear to me: Can i start my god server within rails with an initializer? f.e.
# rails_root/config/initializers/start_god.rb
system 'god -c /www/rails_root/config/god.config'
I tried it in my development environment and as i wanted, the server runs even if i exit the rails server.
But is there any caveat when running this in production mode?
Thanks for your opinion!
p.s. I DONT WANT TO USE CRON! This solution is perfect to me and i dont want to change to another scheduler/queue/background job system!
Using a Rails initializer probably isn’t the best way to start that process, it’s not really what they were intended for. Have you looked into Foreman with Procfile? It might suit you.
http://ddollar.github.com/foreman/