ladjs/graceful

Name: graceful

Owner: Lad

Description: Gracefully exit server (Koa), database (Mongo/Mongoose), and job scheduler (Agenda)

Created: 2017-09-11 01:57:31.0

Updated: 2017-12-05 21:51:36.0

Pushed: 2017-12-01 21:16:44.0

Homepage: https://lad.js.org

Size: 60

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

@ladjs/graceful

build status code coverage code style styled with prettier made with lass license

Gracefully exit server (Koa), database (Mongo/Mongoose), and job scheduler (Agenda)

Table of Contents
Install

npm:

install @ladjs/graceful

yarn:

 add @ladjs/graceful
Usage

Using this package will bind process event listeners when graceful.listen() is called:

This package also prevents multiple process/SIG events from triggering multiple graceful exits. Only one graceful exit can occur at a time.

An example below shows usage showing server, redisClient, mongoose, and agenda options all being passed.

Please note that NONE of these are required, as each one is completely optional and independent.

However if you have both mongoose and agenda defined, it knows to stop agenda first using stop-agenda, then disconnect mongoose.

t http = require('http');

t Graceful = require('@ladjs/graceful');
t Mongoose = require('@ladjs/mongoose');
t Koa = require('koa');
t redis = require('redis');
t Agenda = require('agenda');

t app = new Koa();
t agenda = new Agenda();

server = http.createServer(app.callback());
er = server.listen();

t redisClient = redis.createClient();

t mongoose = new Mongoose({ agenda }).mongoose;

t graceful = new Graceful({

 uses `server.close` for graceful exit
rver,

 uses `redisClient.quit` for graceful exit
disClient,

 uses `mongoose.disconnect` for graceful exit
ngoose,

 uses `stop-agenda` package for graceful exit
enda,

 default logger (you can also use `new Logger()` from @ladjs/logger)
gger: console,

 options get passed to `stop-agenda`
 <https://github.com/ladjs/stop-agenda>
opAgenda: {},

 max time allowed in ms for graceful exit
meoutMs: 5000


eful.listen();
Contributors

| Name | Website | | ————– | ————————– | | Nick Baugh | http://niftylettuce.com/ |

License

MIT © Nick Baugh


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.