Module: Sequel::StatementTimeout
- Defined in:
- lib/sequel/extensions/statement_timeout.rb
Instance Method Summary collapse
Instance Method Details
#with_statement_timeout(timeout_seconds = 20) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sequel/extensions/statement_timeout.rb', line 3 def with_statement_timeout(timeout_seconds = 20) # Might not have postgres class loaded, use class name if self.class.name == "Sequel::Postgres::Database" # Don't want to use a transaction because this will often be a read and a transaction is unnecessary. # Also, when using it for clean, want to control the transactions outside this. current_statement_timeout = execute("show statement_timeout") { |r| r.first.values.first } run("SET statement_timeout = '#{timeout_seconds}s'") begin yield ensure run("SET statement_timeout = '#{current_statement_timeout}'") end else yield end end |