Module: RetryOnDeadlock

Defined in:
lib/retry_on_deadlock.rb,
lib/retry_on_deadlock/core.rb,
lib/retry_on_deadlock/version.rb,
lib/retry_on_deadlock/configuration.rb

Defined Under Namespace

Classes: Configuration, Error

Constant Summary collapse

WAIT_TIMES =
[0, 1, 2, 4, 8, 16, 32]
VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



15
16
17
# File 'lib/retry_on_deadlock.rb', line 15

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Configure the gem

Yields:



18
19
20
21
# File 'lib/retry_on_deadlock.rb', line 18

def configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
end

Instance Method Details

#should_retry?(kwargs) ⇒ Boolean

Helper method to determine if retry should be attempted

Returns:

  • (Boolean)


5
6
7
# File 'lib/retry_on_deadlock/core.rb', line 5

def should_retry?(kwargs)
  kwargs[:retry_on_deadlock] != false && (RetryOnDeadlock.configuration.always_retry || kwargs[:retry_on_deadlock])
end

#transaction(*args, **kwargs, &block) ⇒ Object

Retries a transaction if a deadlock is detected.

Parameters:

  • args (Array)

    Arguments passed to the transaction.

  • kwargs (Hash)

    Keyword arguments, including ‘retry_on_deadlock`.

  • block (Proc)

    The block to execute within the transaction.



13
14
15
16
17
18
19
# File 'lib/retry_on_deadlock/core.rb', line 13

def transaction(*args, **kwargs, &block)
  if should_retry?(kwargs)
    transaction_with_lock_handling(*args, **kwargs.merge(retry_count: 0), &block)
  else
    super(*args, **kwargs.except(:retry_on_deadlock), &block)
  end
end