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

zk-distributed-lock

v1.0.0

Published

<h1 align="center"> ZK-Distributed-Lock </h1>

Downloads

2

Readme

Description

[pipeline status [coverage report

This project implements a Distributed Lock system using Zookeeper. The Project Allows you to acquire lock and to the task while other resources won't be able to acquire it at the same time.

Read more about zookeeper at. https://zookeeper.apache.org/

Contents

Getting_Started

Prerequisites

This project requires Node.js 10 or later.

Install

Install all required packages with

npm i zk-distributed-lock

Now compile the typescript code:

npm run build

Usage

Create an instance of the DistributedLock class

  this.lock = new DistributedLock(zkConnectString, this.lockPath);

Register the events handler if you want.

Acquire and release the lock the Lock,

    await this.lock.acquireLock( (error) => {
      if (error) {
        console.error('Failed to acquire lock:', error);
        return;
      }

      console.log('Lock acquired, doing some work...');
      this.response = "Lock Acquired";
      // Do some work here...

      this.lock.releaseLock(this.lockPath, (error) => {
        if (error) {
          console.error('Failed to release lock:', error);
          return 'Failed to release lock:';
        } else {
          console.log('Lock released');
          this.response = "Lock released";

          return 'task done';
        }
      });
      return 'task done';
    });

Optional parameter

 const optionsRetry:DistributedLockOptions = {
    logger: logger, // your custom logger
    retryCount: 2, // number of times it should retry. put  0 is default
    retryAfter: 2000 , // time in miliseconds between retries.  0 is default
  };

After this even if multiple Instances of your applications are running still only one resource will be able to acquire the lock.

Testing

npm run test:exit

Unit Tests

Unit tests are using

  • Mocha as framework
  • chai as assertion library
  • nyc for test coverage detection.

In order to run just the mocha tests, use

npm run test

In order both run unit tests and test coverage detection, use:

npm run test:ci

Both command will automatically build the project before testing. Unit test results are reported by mochawesome in html format and stored in the root folder under /mochawesome-report. The coverage report can be found in html format in /coverage

Note : You need to have zookeeper running. Here's a docker image this i use

docker run --name my-zookeeper -p 2182:2181 -d zookeeper

Team

License

MIT

This repository was generated by tmpo