Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created September 30, 2011 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkeepers/1254234 to your computer and use it in GitHub Desktop.
Save bkeepers/1254234 to your computer and use it in GitHub Desktop.
Theoretical plugin API for Qu
module AutoRetry
include Qu::Plugin
configure do
def autoretry(*errors)
self.config = {:limit => 3}.merge!(errors.extract_options!)
errors << Exception if errors.empty?
config[:errors] = errors
before :failure, :try_again
end
end
def try_again(e)
if errors.any? {|error| error === e }
data[:retries] += 1
if data[:retries] <= config[:limit]
Qu.requeue self
halt # don't report the error yet
end
end
end
end
# Declare plugin for all Jobs
Qu::Job.plugin AutoRetry
class ProcessPresentation < Qu::Job
autoretry Timeout::Error, :times => 5
attr_reader :presentation
def initialize(presentation_id)
@presentation = Presentation.find(presentation)
end
def perform
# …
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment