class Rethinker::QueryRunner::DatabaseOnDemand

Public Instance Methods

call(env) click to toggle source
# File lib/rethinker/query_runner/database_on_demand.rb, line 2
def call(env)
  @runner.call(env)
rescue RuntimeError => e
  if e.message =~ /^Database `(.+)` does not exist\.$/
    # RethinkDB may return an FIND_DB not found immediately
    # after having created the new database, Be patient.
    # TODO Unit test that thing
    # Also, should we be counter based, or time based for the timeout ?
    Rethinker.db_create $1 unless env[:db_find_retries]
    env[:db_find_retries] ||= 0
    retry if (env[:db_find_retries] += 1) < 10
  end
  raise e
end