Module: Mongoid::Locking::Retry
- Defined in:
- lib/mongoid/locking/retry.rb
Overview
Gives the ability to retry a block of code a specified number of times when a Mongoid::StaleObjectError is raised.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#with_locking(max_retries: 3) ⇒ Object
Retries the block of code a specified number of times when a Mongoid::StaleObjectError is raised.
Class Method Details
.included(base) ⇒ Object
7 8 9 |
# File 'lib/mongoid/locking/retry.rb', line 7 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#with_locking(max_retries: 3) ⇒ Object
Retries the block of code a specified number of times when a Mongoid::StaleObjectError is raised.
This method will reload the document before each block execution.
26 27 28 29 30 31 |
# File 'lib/mongoid/locking/retry.rb', line 26 def with_locking(max_retries: 3) self.class.with_locking(max_retries: max_retries) do reload yield end end |