Module: DynamoDBMutex::Lock
Constant Summary collapse
- TABLE_NAME =
'dynamodb-mutex'
Instance Attribute Summary
Attributes included from Logging
Instance Method Summary collapse
Instance Method Details
#with_lock(name = 'default.lock', opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dynamodb_mutex/lock.rb', line 14 def with_lock name = 'default.lock', opts = {} opts[:stale_after] ||= 10 # seconds opts[:wait_for_other] ||= 1 # seconds opts[:polling_interval] ||= 0.1 # seconds if create(name, opts) begin Timeout::timeout(opts[:stale_after]) { return(yield) } ensure delete(name) end else raise LockError, "Unable to acquire #{name} after #{opts[:wait_for_other]} seconds" end end |