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

@clickup/distributed-locker

v2.10.296

Published

Ensures that some long-running job with an unique key is not double scheduled in the cluster.

Downloads

18

Readme

distributed-locker: ensures that some long-running job with an unique key is not double scheduled in the cluster

See also Full API documentation.

As opposed to the popular redlock algorithm, the library also tracks per-process liveness (in a separate Node thread), so the locks from a dead process are quickly reported as free to the rest of the cluster as soon as the process dies. This is extremely convenient when doing cluster-wide deployments or individual worker process restarts.

Main features:

  1. Resilient to event loop blocking in the worker process, because the lock TTL is high (5 minutes by default).
  2. Despite the long lock TTL, the rest of the cluster quickly (seconds) understands that some job is dead on some other machine, so it can be quickly re-picked-up by another worker somewhere else.
  3. Supports "seppuku": in an event when something goes south, and a lock gets taken over (e.g. due to connectivity issues), the old lock owner automatically kill itself as soon as possible and doesn't continue double-working.
  4. Way more performant than Bull, and does the job of acquiring cluster-wide exclusive locks really well.

Example

export const db = new RedisDatabase(
  // You can also use Redis Cluster here.
  new Redis({
    host: process.env.REDIS_WORKER_HOST,
    port: process.env.REDIS_WORKER_PORT,
    password: process.env.REDIS_WORKER_PASSWORD,
    keyPrefix: "locker:",
  })
);

const locker = new Locker({
  database: {
    moduleName: __file,
    exportName: "db",
  },
});

// ...

const res = await locker.acquireAndRun("job-key", async (heartbeat) => {
  while (shouldContinue()) {
    await doSomeWork();
    // 1. Reports that the job is still running to refresh the lock.
    // 2. If someone takes over (e.g. a network blip or event loop
    //    blockage), kills itself by throwing LockError exception.
    await heartbeat();
  }
});
// res is now either { status: LockStatus.SUCCESS } 
// or { status: LockStatus.SOMEONE_ELSE_HOLDS_LOCK }