Class: PgDice::QueryExecutor
- Inherits:
-
Object
- Object
- PgDice::QueryExecutor
- Defined in:
- lib/pgdice/query_executor.rb
Overview
Wrapper class around pg_connection to reset connection on PG errors
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #call(query) ⇒ Object
-
#initialize(logger:, connection_supplier:) ⇒ QueryExecutor
constructor
A new instance of QueryExecutor.
Constructor Details
#initialize(logger:, connection_supplier:) ⇒ QueryExecutor
Returns a new instance of QueryExecutor.
9 10 11 12 |
# File 'lib/pgdice/query_executor.rb', line 9 def initialize(logger:, connection_supplier:) @logger = logger @connection_supplier = connection_supplier end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/pgdice/query_executor.rb', line 7 def logger @logger end |
Instance Method Details
#call(query) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/pgdice/query_executor.rb', line 14 def call(query) @connection_supplier.call.exec(query) rescue PG::Error => e logger.error { "Caught error: #{e}. Going to reset connection and try again" } @connection_supplier.call.reset @connection_supplier.call.exec(query) end |