adios

    2.1.0 • Public • Published

    Adios

    Greenkeeper badge

    Build Status Coverage Status

    A module for notifying clustered workers for clean shutdowns.

    This is accomplished by using domain sockets/var/run/adios.sock by default – which has the added benefit of not sending messages over application specific IPC channels. This means you don't have to filter out messages from adios in any process.on('message') listeners.

    Note: On Windows, the local domain is implemented using a named pipe. The path must refer to an entry in \\?\pipe\ or \\.\pipe\. Therefore, you must initialize adios with a path in this space if you are running on a Windows machine.

    Usage

    'use strict';
    const cluster = require('cluster');
    const http = require('http');
    const Adios = require('adios');
     
    if (cluster.isMaster) {
      Adios.master.init()
        .then(() => {
          let worker = cluster.fork();
        });
    }
    else {
      let server = http.createServer();
      Adios.child.init(() => {
        return new Promise(resolve => {
          server.close(resolve);
        });
      })
        .then(() => {
          server.listen(3000);
        });
    }

    API

    • Adios.master.init([path]) - The initialize function for adios masters. Sets up a server for IPC with clustered workers. Note: there can be only one.

      • path - (optional) The socket path to use. Defaults to /var/run/adios.sock
      • config - (optional) A configuration object for the master process. Contains:
        • timeout: time in milliseconds before a child will be force closed. Default: 10000, 10 seconds.

      Returns a promise that resolves when the server is listening.

    • Adios.master.kill(pid) - Method to kill a worker by process id

      • pid - The process id to kill
    • Adios.master.term(pid) - Method to terminate a worker by process id, this will call the graceful shutdown defined by the worker.

      • pid - The process id to terminate

      Returns a promise that resolves when the worker is terminated.

    • Adios.child.init(cleanCb[, path]) - The initialize function for adios children. Sets up a connection to the master. Note: there can be only one per process and it must be running on a child process.

      • cleanCb - The method to execute when the master is notifying of a shutdown. Must return a promise that resolves when work is done.
      • path - (optional) The socket path to use. Defaults to /var/run/adios.sock

      Returns a promise that resolves when the connection with the master has been established.

    Install

    npm i adios

    DownloadsWeekly Downloads

    28

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    221 kB

    Total Files

    15

    Last publish

    Collaborators

    • elliotttf