Module: Moped::Failover::Retry

Extended by:
Retry
Included in:
Retry
Defined in:
lib/moped/failover/retry.rb

Overview

Retry is for the case when we get exceptions around the connection, and want to make another attempt to try and resolve the issue.

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#execute(exception, node) ⇒ Object

Executes the failover strategy. In the case of retry, we disconnect and reconnect, then try the operation one more time.

Examples:

Execute the retry strategy.

Moped::Failover::Retry.execute(exception, node)

Parameters:

  • exception (Exception)

    The raised exception.

  • node (Node)

    The node the exception got raised on.

Returns:

  • (Object)

    The result of the block yield.

Raises:

Since:

  • 2.0.0



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moped/failover/retry.rb', line 26

def execute(exception, node)
  node.disconnect unless exception.is_a?(Errors::PoolTimeout)
  begin
    node.connection do |conn|
      yield(conn) if block_given?
    end
  rescue Errors::PoolTimeout => e
    raise Errors::ConnectionFailure.new e
  rescue Exception => e
    node.down!
    raise(e)
  end
end