Class: Rethinker::QueryRunner::DatabaseOnDemand
- Inherits:
-
Middleware
- Object
- Middleware
- Rethinker::QueryRunner::DatabaseOnDemand
- Defined in:
- lib/rethinker/query_runner/database_on_demand.rb
Instance Method Summary collapse
Methods inherited from Middleware
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 |
# File 'lib/rethinker/query_runner/database_on_demand.rb', line 2 def call(env) @runner.call(env) rescue RuntimeError => e if e. =~ /^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 |