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
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Configure the gem.
Instance Method Summary collapse
-
#should_retry?(kwargs) ⇒ Boolean
Helper method to determine if retry should be attempted.
-
#transaction(*args, **kwargs, &block) ⇒ Object
Retries a transaction if a deadlock is detected.
Class Attribute Details
.configuration ⇒ Object
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
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
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.
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 |