Class: PoolLint::Inspectors::PostgreSQLCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/poollint/inspectors/postgresql_capture.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ PostgreSQLCapture

Returns a new instance of PostgreSQLCapture.



6
7
8
# File 'lib/poollint/inspectors/postgresql_capture.rb', line 6

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#call(connection, names) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/poollint/inspectors/postgresql_capture.rb', line 10

def call(connection, names)
  snapshot = nil
  ExecutionState.while_inspecting do
    connection.transaction(requires_new: true, joinable: false) do
      original_timeout = capture_statement_timeout(connection, names)
      apply_timeout(connection)
      snapshot = yield
      restore_statement_timeout(snapshot, original_timeout)
      raise ActiveRecord::Rollback
    end
  end
  snapshot
rescue StandardError => e
  raise InspectionTimeout, "inspection exceeded statement_timeout" if query_canceled?(e)

  raise
end