cluster-watchdog
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Cluster Watchdog

npm version npm downloads

Cluster Watchdog is a lightweight package for managing active-standby clusters

Installation

To install Cluster Watchdog, run one of the following commands:

using npm:

npm i cluster-watchdog

using yarn:

yarn add cluster-watchdog

using pnpm:

pnpm add cluster-watchdog

Usage

import { initWatchdog, runWhenActive } from 'cluster-watchdog';
import { Client, createClient } from 'node-zookeeper-client';

// Create a ZooKeeper client and connect to it
const createZookeeperClient = (connectionString: string): Promise<Client> =>
  new Promise<Client>((resolve) => {
    const client: Client = createClient(connectionString);
    client.once('connected', () => resolve(client));
  });

// A function that will execute only if the service is the primary/active
const poller = runWhenActive(async () => {
  try {
    /*
            do polling/db writing
         */
    setTimeout(poller, 1000);
  } catch (e) {
    setTimeout(poller, 3000);
  }
});

(async () => {
  const client = await createZookeeperClient('localhost:2181');

  // Initiate Watchdog Cluster
  await initWatchdog({
    client,
    sequencePath: '/path',
    threshold: 5000,
    log: console.log,
  });

  // Call the function
  poller();
})();

License

Cluster Watchdog is licensed under the MIT License.

Package Sidebar

Install

npm i cluster-watchdog

Weekly Downloads

5

Version

0.0.3

License

MIT

Unpacked Size

12.1 kB

Total Files

7

Last publish

Collaborators

  • remez254