Sha256: d61bcd3509cae70b4130df730062eca554aab501c6e7898cdaa6b95bbd28576c
Contents?: true
Size: 855 Bytes
Versions: 12
Compression:
Stored size: 855 Bytes
Contents
module Sequel module StatementTimeout 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 end Database.register_extension(:statement_timeout){|db| db.extend(StatementTimeout) } end
Version data entries
12 entries across 12 versions & 1 rubygems