@github-automations/datastore-lock

1.0.0 • Public • Published

A distributed lock

This is a simple lock library backed by Google Cloud Datastore.

Github bots can have multiple instances and sometimes those instances are modifying the same target (issue, pull request, etc). This simple library allows the bot to acquire a lock on sth.

Usage

Install

npm i @github-automations/datastore-lock

Usage

import {DatastoreLock} from '@github-automations/datastore-lock';

// Most of the cases, you can just pass `lockId` and `target`.
// `lockId` is usually the bot name.
// `target` is the target for the lock.

const lockId = 'blunderbuss';
const target = context.payload.pull_request.url;

const lock = new DatastoreLock(lockId, target);
const result = await lock.acquire();
if (!result) {
	// failure
}
// Do your stuff, and release the lock after you've done.
result = await lock.release();
// The lock will become stale after 20 seconds.
// You can pass the 3rd argument for longer expiry, up to 60 seconds.
const lock2 = new DatastoreLock(lockId, target, 60 * 1000);

Package Sidebar

Install

npm i @github-automations/datastore-lock

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Unpacked Size

24.9 kB

Total Files

7

Last publish

Collaborators

  • google-wombot