Name: process-manager
Owner: Uphold
Description: A node.js process manager using co.
Created: 2017-01-05 18:46:10.0
Updated: 2017-03-23 17:20:35.0
Pushed: 2018-03-09 17:00:32.0
Size: 62
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A node.js process manager. This package handles a process's lifecycle, from running to exiting, by handling errors and exceptions, as well as graceful shutdowns.
Install the package via yarn:
rn add '@uphold/process-manager'
Or npm:
m install '@uphold/process-manager' --save
To use process-manager
simply require it in your project.
t processManager = require('process-manager');
sync/await
essManager.once(async () => {
ait foo.bar();
romise
essManager.once(() => new Promise((resolve, reject) => {
o.bar(err => {
if (err) return reject();
return resolve();
;
And it will now manage your node process.
This lifecycle is used to loop over a given function.
fn
(Function): the function to run.[options]
(object): the options object.[options.interval=0]
(integer): how long to wait (in miliseconds) before restarting the function.t processManager = require('process-manager');
essManager.loop(async () => {
nsole.log(await client.getSomeInfo());
interval: 600 });
This lifecycle is used to get a function suited for using with an event emitter. It does not exit unless something goes wrong.
fn
(Function): the function to run.t processManager = require('process-manager');
c function handler(value) {
nsole.log(await client.getInfo(value));
nt.on('event', processManager.on(handler));
This lifecycle is used to a given function and exit.
fn
(Function): the function to run.t processManager = require('process-manager');
essManager.once(async () => {
ait client.doWork();
This function can be called to trigger a process shutdown. If passed an error as an optional argument, it will save it to the errors array. This function will only start the shutdown process once, any extra calls will be ignored, although it will still save the error if one is passed.
If called with { force: true }
it will skip waiting for running processes and immediately start disconnecting.
[args]
(object): the arguments object.[args.error]
(Error): an error to add to the errors array.[args.force]
(Boolean): a boolean that forces the shutdown to skip waiting for running processes.t processManager = require('process-manager');
essManager.shutdown({ error: new Error('Error') });
Currently there are three hooks that can be used to call external code during the shutdown process. If a hook takes longer than 30 seconds to return, it will timeout and continue with the shutdown process.
This hook is called during shutdown, after all running processes have stopped. It should be used to drain connections if the process is running a server.
This hook is called after drain
and it's where handlers should be added to close running services (ex.: database connections, persistent connections, etc).
This hook is called right before the process exits. It passes an array of errors as an argument to the handler function, and should be used to handle errors before exiting.
This function is used to add a hook for one of the types described above.
args.handler
(Function): a function that returns a value or a thenable.args.type
(string): the hook type.[args.name='a handler']
(string): identifies the hook.t processManager = require('process-manager');
essManager.addHook({ handler: () => 'result', type: <hook-type> });
essManager.addHook({ handler: () => Promise.resolve('result'), type: <hook-type> });
The recommended way to report errors to sentry is by adding an exit
hook and sending each error using a promisified captureException
.
t Promise = require('bluebird');
t raven = Promise.promisifyAll(require('raven'));
n.config('https://******@sentry.io/<appId>').install();
essManager.addHook({
ndler: errors => Promise.map(errors, error => raven.captureExceptionAsync(error)),
me: 'sentry',
pe: 'exit'
Enable verbose debugging by setting the DEBUG environment variable to DEBUG=process-manager.
m version [<new version> | major | minor | patch] -m "Release %s"`
To test using a local version of node
, run:
rn test
MIT