zolter
zolter

Reputation: 7160

Auto restart rake task if it give exception

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

Answers (3)

zolter
zolter

Reputation: 7160

In my case God gem is what I need, thank you for your answers!

Upvotes: 2

makaroni4
makaroni4

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

Andrew Nesbitt
Andrew Nesbitt

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

Related Questions