Ruby Stuff: Use retry to restart a begin rescue block
February 11th, 2010
I recently needed to be able retry a begin block and was simply nesting begins within begins, then I ran across this little Ruby gym. The retry, http://www.tutorialspoint.com/ruby/ruby_exceptions.htm.
begin
@calendarapi.calendars
rescue Exception => ex
logger.info ex
switch_ssl()
retry
end
Obviously this bit of code could end in a continuous loop so be careful to add a little logic to ensure a clean exit.
Paul June 13th, 2011
I love Ruby gyms. Begin is starting the exercise, rescue is the spotter and retry is the sets.
In all seriousness, stumbled onto this blog looking for retries after a delay. ‘sleep’ seems to lock up the Rails process. If you nice gentleman or anyone else that stumbles onto this page has any ideas, please leave them :)