Class: TransactionEventStoreMongoid::Lock
- Inherits:
-
Object
- Object
- TransactionEventStoreMongoid::Lock
- Includes:
- Mongoid::Document
- Defined in:
- lib/transaction_event_store_mongoid/lock.rb
Instance Method Summary collapse
Instance Method Details
#with_lock(stream) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/transaction_event_store_mongoid/lock.rb', line 12 def with_lock(stream) begin lock = self.class.create(_id: stream, ts: Time.now.utc) rescue ::Mongo::Error::OperationFailure raise ::TransactionEventStore::CannotObtainLock end yield if block_given? ensure lock.delete if lock.present? end |