npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datastore-lock

v0.1.1

Published

distributed lock based on google datastore

Downloads

20

Readme

datastore-lock

A lightweight implementation of the distributed lock which is based on Google Datastore.

Where to use?

Mainly useful for the application level distributed locks.

Example Scenario: you have a an application which sends an email based on an external event. If your application is running multiple instances of it and external event triggers an action in all the instances, you might be required to use distributed locks to ensure that NOT all instances end up sending the email and only one mail is being sent.

What does it offer?

It allows an application to acquire lock for a leased period of time (by default 1 minute, but can be configured using options) which will prevent other application instance who complete for it from acquiring the lock, till the first application either releases the lock or leased time gets expired.

How to use?

  1. Download via npm npm install datastore-lock.
  2. Instantiate
const dslock = new DSLock(options);
  1. acquire lock
dslock.lock()
    .then(locked => {
        if(locked){
            // lock acquired, do something exclusively
        } else{
            // failed to acquire the lock, not safe to run exclusive logic
        }
    });
  1. release the lock once done
dslock.unlock()
    .then(unlocked => {
        if(unlocked){
            // lock released
        } else{
            // could not release the lock
        }
    });

Options

while instantiation you can pass options to configure the datastore-lock

const dslock = new DSLock(options)

options object can have following values:

  • projectId - (required if dsClient is not set) google project id which will be used to connect to Google Datastore
  • leaseFor - (optional) max number of seconds the lock would be available for, after this time runs out and lock is not released, it will automatically get expired. Default value is 60.
  • dsClient - (required if projectId is not set) an instance of Datastore client as described here.
  • keyFilename - (optional) file path of the Google service account credentials, alternatively you can set GOOGLE_APPLICATION_CREDENTIALS env variable.
  • lockKeyName - (optional) name of the key which will be used while creating the lock in the Datastore. Useful in cases where you want more than one locks in the same application for different functionalities. Default value if lockKeyName.
  • namespace - (optional) Google Datastore namespace to create and store the lock. Default value is dslock.