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, 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, opts = {} opts[:ttl] ||= 10 opts[:block] ||= 1 opts[:sleep] ||= 0.1 if create(name, opts) begin Timeout::timeout(opts[:ttl]) { return(yield) } ensure delete(name) end else raise LockError, "Unable to hold #{name} after #{opts[:block]} ms" end end |