0.0.2 • Published 3 years ago

node-cluster-utils v0.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
3 years ago

Node Cluster Utils

Install

$ npm install https://github.com/4000D/node-cluster-utils.git

implemente nodejs app and run with pm2 cluster mode.

Usage

const { withLock } = require("node-cluster-utils");

withLock({
  // lockFilePath: "path/to/lock/file",
  f: () => {
    setInterval(() => {
      console.log("hello", process.pid);
    }, 1000);

    return new Promise(() => {}); // run 1 node instance acquire lock forever
  },
});
import { withLock } from "node-cluster-utils";

withLock({
  // lockFilePath: "path/to/lock/file",
  f: () => {
    setInterval(() => {
      console.log("hello", process.pid);
    }, 1000);

    return new Promise<void>(() => {}); // run 1 node instance acquire lock forever
  },
});