Class: Synapse::Command::RetryingCallback

Inherits:
CommandCallback show all
Defined in:
lib/synapse/command/gateway/retrying_callback.rb

Overview

Implementation of a callback that will retry the dispatch of a command if execution results in an exception

This callback is not meant to be used directly. Use a command gateway implementation instead.

Instance Method Summary collapse

Constructor Details

#initialize(delegate, command, retry_scheduler, command_bus) ⇒ undefined

Parameters:



13
14
15
16
17
18
19
20
21
22
# File 'lib/synapse/command/gateway/retrying_callback.rb', line 13

def initialize(delegate, command, retry_scheduler, command_bus)
  @command = command
  @delegate = delegate
  @retry_scheduler = retry_scheduler

  @failures = Array.new
  @dispatcher = proc do
    command_bus.dispatch_with_callback command, self
  end
end

Instance Method Details

#on_failure(exception) ⇒ undefined

Parameters:

  • exception (Exception)

    The cause of the failure

Returns:

  • (undefined)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/synapse/command/gateway/retrying_callback.rb', line 32

def on_failure(exception)
  @failures.push exception

  begin
    unless exception.is_a? RuntimeError and
        @retry_scheduler.schedule @command, @failures, @dispatcher
      @delegate.on_failure exception
    end
  rescue
    @delegate.on_failure $!
  end
end

#on_success(result) ⇒ undefined

Parameters:

  • result (Object)

    The result from the command handler

Returns:

  • (undefined)


26
27
28
# File 'lib/synapse/command/gateway/retrying_callback.rb', line 26

def on_success(result)
  @delegate.on_success result
end