lib/dispatch-rider/handlers/base.rb in dispatch-rider-1.0.3 vs lib/dispatch-rider/handlers/base.rb in dispatch-rider-1.1.4

- old
+ new

@@ -1,18 +1,56 @@ module DispatchRider module Handlers class Base include NamedProcess extend InheritanceTracking + + class << self + def set_default_retry( amount ) + define_method(:retry_timeout) do + amount + end + end + end + + attr_reader :raw_message - def do_process(options) + def do_process(raw_message) with_named_process(self.class.name) do - process(options) + @raw_message = raw_message + process(raw_message.body) end + rescue Exception => e + self.retry if self.retry_on_failure? + raise e end - def process(options) + def process(message) raise NotImplementedError, "Method 'process' not overridden in subclass!" + end + + protected + + def extend_timeout(timeout) + raw_message.extend_timeout(timeout) + end + + def return_to_queue + raw_message.return_to_queue + end + + def retry + timeout = retry_timeout + case timeout + when :immediate + return_to_queue + else + extend_timeout(timeout) + end + end + + def retry_on_failure? + self.respond_to? :retry_timeout end end end end