@ladjs/graceful
Advanced tools
Comparing version 1.0.1 to 1.0.3
37
index.js
@@ -10,2 +10,3 @@ const debug = require('debug')('@ladjs/graceful'); | ||
bulls: [], | ||
brees: [], | ||
logger: console, | ||
@@ -32,2 +33,4 @@ timeoutMs: 5000, | ||
this.stopBulls = this.stopBulls.bind(this); | ||
this.stopBree = this.stopBree.bind(this); | ||
this.stopBrees = this.stopBrees.bind(this); | ||
this.exit = this.exit.bind(this); | ||
@@ -38,3 +41,3 @@ } | ||
// handle warnings | ||
process.on('warning', warning => { | ||
process.on('warning', (warning) => { | ||
// <https://github.com/pinojs/pino/issues/833#issuecomment-625192482> | ||
@@ -49,3 +52,3 @@ warning.emitter = null; | ||
// handle uncaught exceptions | ||
process.once('uncaughtException', err => { | ||
process.once('uncaughtException', (err) => { | ||
this.logger.error(err); | ||
@@ -57,3 +60,3 @@ process.exit(1); | ||
// <http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#windows-graceful-stop> | ||
process.on('message', async message => { | ||
process.on('message', async (message) => { | ||
if (message === 'shutdown') { | ||
@@ -68,3 +71,3 @@ this.logger.info('Received shutdown message'); | ||
// <https://github.com/remy/nodemon#controlling-shutdown-of-your-script> | ||
['SIGTERM', 'SIGHUP', 'SIGINT', 'SIGUSR2'].forEach(sig => { | ||
['SIGTERM', 'SIGHUP', 'SIGINT', 'SIGUSR2'].forEach((sig) => { | ||
process.once(sig, async () => { | ||
@@ -86,3 +89,3 @@ await this.exit(sig); | ||
await Promise.all( | ||
this.config.servers.map(server => this.stopServer(server)) | ||
this.config.servers.map((server) => this.stopServer(server)) | ||
); | ||
@@ -104,3 +107,3 @@ } | ||
await Promise.all( | ||
this.config.redisClients.map(client => this.stopRedisClient(client)) | ||
this.config.redisClients.map((client) => this.stopRedisClient(client)) | ||
); | ||
@@ -119,3 +122,3 @@ } | ||
await Promise.all( | ||
this.config.mongooses.map(mongoose => this.stopMongoose(mongoose)) | ||
this.config.mongooses.map((mongoose) => this.stopMongoose(mongoose)) | ||
); | ||
@@ -133,5 +136,19 @@ } | ||
async stopBulls() { | ||
await Promise.all(this.config.bulls.map(bull => this.stopBull(bull))); | ||
await Promise.all(this.config.bulls.map((bull) => this.stopBull(bull))); | ||
} | ||
stopBree(bree) { | ||
try { | ||
bree.stop(); | ||
} catch (err) { | ||
this.config.logger.error(err); | ||
} | ||
} | ||
stopBrees() { | ||
for (const bree of this.config.brees) { | ||
this.stopBree(bree); | ||
} | ||
} | ||
async exit(code) { | ||
@@ -169,3 +186,5 @@ if (code) this.logger.info(`Gracefully exiting from ${code}`); | ||
// bulls | ||
this.stopBulls() | ||
this.stopBulls(), | ||
// brees | ||
this.stopBrees() | ||
]); | ||
@@ -172,0 +191,0 @@ this.logger.info('Gracefully exited'); |
{ | ||
"name": "@ladjs/graceful", | ||
"description": "Gracefully exit server (Koa), database (Mongo/Mongoose), and job scheduler (Redis/Bull)", | ||
"version": "1.0.1", | ||
"description": "Gracefully exit server (Koa), database (Mongo/Mongoose), Bree job schedulers, and Bull job schedulers", | ||
"version": "1.0.3", | ||
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)", | ||
@@ -22,16 +22,16 @@ "bugs": { | ||
"devDependencies": { | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/config-conventional": "^8.1.0", | ||
"ava": "^2.3.0", | ||
"codecov": "^3.5.0", | ||
"cross-env": "^5.2.1", | ||
"eslint": "6.3.0", | ||
"@commitlint/cli": "^9.0.1", | ||
"@commitlint/config-conventional": "^9.0.1", | ||
"ava": "^3.10.1", | ||
"codecov": "^3.7.0", | ||
"cross-env": "^7.0.2", | ||
"eslint": "7.4.0", | ||
"eslint-config-xo-lass": "^1.0.3", | ||
"fixpack": "^2.3.1", | ||
"husky": "^3.0.5", | ||
"lint-staged": "^9.2.5", | ||
"nyc": "^14.1.1", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-github": "^0.0.16", | ||
"xo": "^0.24.0" | ||
"fixpack": "^3.0.6", | ||
"husky": "^4.2.5", | ||
"lint-staged": "^10.2.11", | ||
"nyc": "^15.1.0", | ||
"remark-cli": "^8.0.0", | ||
"remark-preset-github": "^2.0.2", | ||
"xo": "^0.32.1" | ||
}, | ||
@@ -49,4 +49,30 @@ "engines": { | ||
"keywords": [ | ||
"@ladjs/graceful", | ||
"lass" | ||
"bree", | ||
"bull", | ||
"close", | ||
"database", | ||
"exception", | ||
"exit", | ||
"express", | ||
"force", | ||
"graceful", | ||
"handler", | ||
"kill", | ||
"koa", | ||
"lad", | ||
"lass", | ||
"mongo", | ||
"monitor", | ||
"node", | ||
"pm2", | ||
"process", | ||
"queue", | ||
"redis", | ||
"reload", | ||
"reloading", | ||
"server", | ||
"sighup", | ||
"sigint", | ||
"uncaught", | ||
"worker" | ||
], | ||
@@ -53,0 +79,0 @@ "license": "MIT", |
@@ -10,3 +10,3 @@ # [**@ladjs/graceful**](https://github.com/ladjs/graceful) | ||
> Gracefully exit server (Koa), database (Mongo/Mongoose), Redis clients, and job scheduler (Redis/Bull) | ||
> Gracefully exit server (Koa), database (Mongo/Mongoose), Redis clients, Bree job schedulers, and Bull job schedulers | ||
@@ -59,3 +59,5 @@ | ||
You can also read more about Bree at <https://github.com/breejs/bree>. | ||
## Contributors | ||
@@ -62,0 +64,0 @@ |
@@ -5,4 +5,4 @@ const test = require('ava'); | ||
test('returns itself', t => { | ||
test('returns itself', (t) => { | ||
t.true(new Graceful() instanceof Graceful); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11483
170
80