Class: ASIR::Transport::Retry

Inherits:
ASIR::Transport show all
Includes:
RetryBehavior, Delegation
Defined in:
lib/asir/transport/retry.rb

Overview

!SLIDE Retry Transport

Constant Summary

Constants included from ASIR::ThreadVariable

ASIR::ThreadVariable::DEBUG, ASIR::ThreadVariable::EMPTY_HASH, ASIR::ThreadVariable::SETTER

Instance Attribute Summary collapse

Attributes included from Delegation

#on_failed_message, #on_send_message_exception, #reraise_first_exception

Attributes included from RetryBehavior

#try_max, #try_sleep, #try_sleep_increment, #try_sleep_max

Attributes inherited from ASIR::Transport

#after_invoke_message, #after_receive_message, #before_send_message, #coder_needs_result_message, #decoder, #encoder, #invoker, #message_count, #needs_message_identifier, #needs_message_timestamp, #on_exception, #on_result_exception, #one_way, #running, #verbose

Attributes included from Log

#_logger

Instance Method Summary collapse

Methods included from Delegation

#_handle_send_message_exception!, #_receive_result, #needs_message_identifier?, #needs_message_timestamp?, #transports

Methods included from RetryBehavior

#with_retry

Methods inherited from ASIR::Transport

#_subclass_responsibility, #initialize, #invoke_message!, #needs_message_identifier?, #needs_message_timestamp?, #receive_message, #receive_result, #send_message, #send_result, #serve_message!, #stop!, #with_server_signals!

Methods included from Log

#_log, #_log_enabled=, #_log_enabled?, #_log_format, #_log_result, enabled, enabled=, included

Methods included from Initialization

#initialize

Methods included from AdditionalData

#[], #[]=, #_additional_data, #additional_data, #additional_data!, #additional_data=, included

Methods included from Message::Delay

#relative_message_delay!, #wait_for_delay!

Methods included from ASIR::ThreadVariable

included, setter

Constructor Details

This class inherits a constructor from ASIR::Transport

Instance Attribute Details

#before_retryObject

Proc to call(transport, message) before retry.



14
15
16
# File 'lib/asir/transport/retry.rb', line 14

def before_retry
  @before_retry
end

#transportObject

The transport to delegate to.



12
13
14
# File 'lib/asir/transport/retry.rb', line 12

def transport
  @transport
end

Instance Method Details

#_send_message(state) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/asir/transport/retry.rb', line 16

def _send_message state
  first_exception = nil
  with_retry do | action, data |
    case action
    when :try
      result = transport.send_message(state.message)
      state.result = Result.new(state.message, result)
    when :rescue #, exc
      first_exception ||= data
      _handle_send_message_exception! transport, state, data
    when :retry #, exc
      before_retry.call(self, state) if before_retry
    when :failed
      @on_failed_message.call(self, state) if @on_failed_message
      if first_exception && @reraise_first_exception
        $! = first_exception
        raise
      end
      nil # fallback to raise RetryError
    end
  end
end