Class: Rethinker::QueryRunner::Connection

Inherits:
Middleware
  • Object
show all
Defined in:
lib/rethinker/query_runner/connection.rb

Instance Method Summary collapse

Methods inherited from Middleware

#initialize

Constructor Details

This class inherits a constructor from Rethinker::QueryRunner::Middleware

Instance Method Details

#call(env) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rethinker/query_runner/connection.rb', line 2

def call(env)
  @runner.call(env)
rescue RuntimeError, Rethinker::Error::DocumentNotSaved => e
  if e.message =~ /cannot perform (read|write): lost contact with master/
    env[:connection_retries] ||= 0
    # TODO sleep in between? timing out should be time based?

    # XXX Possibly dangerous, as we could reexecute a non idempotent operation
    # Check the semantics of the db

    # TODO Unit test
    retry if (env[:connection_retries] += 1) < 10
  end
  raise e
end