0.0.3 • Published 12 months ago

cluster-watchdog v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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.

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago

0.0.0-development

12 months ago