This is an attempt to use DynamoDB as a lock store.
We don't have a 'Locks as a Service' thing yet, so this is an experiment to make the best of what we do have.
Would love to hear of any use of this or if you think it is just a terrible idea to begin with.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install fog-aws-dynamodb-locker
export AWS_ACCESS_KEY_ID=... export AWS_SECRET_ACCESS_KEY=... export DYNAMODB_LOCK_TABLE='my-lock-table'
require 'fog/aws/dynamodb/locker' # first run only Fog::AWS::DynamoDB::Locker.init! # create a lock Fog::AWS::DynamoDB::Locker.lock!('my lock') # => true # try to claim it a second time Fog::AWS::DynamoDB::Locker.lock!('my lock') # => false # release it Fog::AWS::DynamoDB::Locker.release!('my lock') # => true
If a client process dies for any reason, the lock will not be removed. A method will need to be put in place to clear likely deadlocks.
Once again, we need a real 'Locks as a Service'.
- real specs
- set a timestamp on each lock
- allow metadata on each lock
Fog::AWS::DynamoDB::Locker.sweep!(n)to remove all locks that are
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request