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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Gracefully exit server (Koa), database (Mongo/Mongoose), and job scheduler (Agenda)
npm:
install @ladjs/graceful
yarn:
add @ladjs/graceful
Using this package will bind process event listeners when graceful.listen()
is called:
process.on('warning')
- will output via config.logger.warn
process.on('unhandledRejection')
- will output via config.logger.error
process.on('uncaughtException')
- will output via config.logger.error
and process.exit(1)
process.on('message')
- support Windows (e.g. signals not available) and listen for message of shutdown
and then exit gracefullyprocess.on('SIGTERM')
- will exit gracefullyprocess.on('SIGHUP')
- will exit gracefullyprocess.on('SIGINT')
- will exit gracefullyThis 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();
| Name | Website | | ————– | ————————– | | Nick Baugh | http://niftylettuce.com/ |