Skip to content

Instantly share code, notes, and snippets.

@duduribeiro
Created June 1, 2016 16:03
Show Gist options
  • Save duduribeiro/ad553c0d448a00f8faa9e7a92f9c6e66 to your computer and use it in GitHub Desktop.
Save duduribeiro/ad553c0d448a00f8faa9e7a92f9c6e66 to your computer and use it in GitHub Desktop.
Retry on around filter
def retryable(options = {})
opts = { :tries => 1, :on => Exception }.merge(options)
retry_exception, retries = opts[:on], opts[:tries]
begin
return yield
rescue retry_exception
if (retries -= 1) > 0
sleep 2
retry
else
raise
end
end
end
class ApplicationController < ActionController::Base
around_filter :retry_on_timeout
def retry_on_timeout
retryable(:tries => 10, :on => Timeout::Error) do
yield
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment