Created
September 30, 2011 16:10
-
-
Save bkeepers/1254234 to your computer and use it in GitHub Desktop.
Theoretical plugin API for Qu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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