2.0.0 • Published 8 years ago

@aptoma/ddblock v2.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

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
	});