Class: SqlPartitioner::LockWaitTimeoutHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_partitioner/lock_wait_timeout_handler.rb

Class Method Summary collapse

Class Method Details

.with_lock_wait_timeout(adapter, timeout, &block) ⇒ Object

Temporarily sets the ‘@@local.lock_wait_timeout` to the given value, executes the `block`, and restores `@@local.lock_wait_timeout` to its original value.



6
7
8
9
10
11
12
13
14
# File 'lib/sql_partitioner/lock_wait_timeout_handler.rb', line 6

def self.with_lock_wait_timeout(adapter, timeout, &block)
  lock_wait_timeout_before = adapter.select("SELECT @@local.lock_wait_timeout").first
  adapter.execute("SET @@local.lock_wait_timeout = ?", timeout)
  begin
    return block.call
  ensure
    adapter.execute("SET @@local.lock_wait_timeout = ?", lock_wait_timeout_before.to_i)
  end
end