@aptoma/ddblock

Distributed lock using DynamoDB

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
30Oct 6, 2016Sep 26, 2016Minified + gzip package size for @aptoma/ddblock in KB

Readme

DDBLock

Distributed locking using DynamoDB.

Install

npm install @aptoma/ddblock

Preqrequistes

Requires a DynamoDB table with a primary partition key called Name of type String.

Example


    const ddblock = require('@aptoma/ddblock')({
        table: 'MyDynamoTableName',
        ttl: 60,
        aws: {region: 'eu-west-1'}
    });

    ddblock
        .lock('job1')
        .then(() => {
            // do my work
        })
        .then(() => ddblock.unlock('job1'))
        .catch(ddblock.AlreadyLockedError, () => {
            // An active lock aready exists for 'job1'
        });

For local development where the locking mecanism isnt needed you can initiate DDBlock in a disabled mode, lock & unlock will resolve without doing anything.


    const ddblock = require('@aptoma/ddblock')({
        disabled: true,
        table: 'MyDynamoTableName',
        ttl: 60
    });

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.