Reputation: 7160
I have a rake task that must be always run. But sometimes this task can fail. And I need auto restart it? I think I need use God gem or maybe there are other ways to solve this problem?
Upvotes: 1
Views: 1361
Reputation: 2281
It all depends on your problem, but how about pure Ruby solution:
begin
puts "Start"
raise "BOOOM"
rescue Exception => e
puts e.message
sleep(2)
retry
end
Just retry you begin block each time you catch an exception.
Upvotes: 4
Reputation: 6046
If you are using ubuntu you can use upstart quite easily with a config like this:
start on startup
stop on shutdown
pre-start script
cd /var/www/my-app/current
end script
script
exec RAILS_ENV=production bundle exec rake my_task_name
end script
Read more here: http://www.stackednotion.com/blog/2012/02/09/easy-rails-daemons-with-upstart/
Upvotes: 1