refactor: misc changes

This commit is contained in:
Alexis Tyler
2020-02-02 15:28:51 +10:30
parent 00008554a3
commit 6ee6a570d6
2 changed files with 19 additions and 10 deletions
+14 -7
View File
@@ -1,31 +1,38 @@
const path = require('path');
const cluster = require('cluster');
// Show real stack trace in development
if (process.env.NODE_ENV !== 'production') {
require('source-map-support').install({
handleUncaughtExceptions: false
});
}
const RESTART_ATTEMPTS = 10;
let currentRestartAttempt = 0;
if (cluster.isMaster) {
cluster.fork();
cluster.on('exit', (worker, code, signal) => {
cluster.on('exit', (_, code) => {
if (code !== 7) {
process.exit(code);
}
if (currentRestartAttempt < RESTART_ATTEMPTS) {
currentRestartAttempt++;
cluster.fork();
if (currentRestartAttempt >= RESTART_ATTEMPTS) {
console.debug(`No restart attempts left. Exiting.`);
process.exit(1);
}
console.debug(`No restart attempts left. Exiting.`);
process.exit(1);
currentRestartAttempt++;
cluster.fork();
});
}
if (cluster.isWorker) {
// @ts-ignore
const package = require('./package.json');
const { main, name } = package;
const { main } = package;
if (!main) {
console.error('Missing main field in package.json');
+5 -3
View File
@@ -6,8 +6,8 @@
"author": "Alexis Tyler <xo@wvvw.me> (https://wvvw.me/)",
"license": "UNLICENSED",
"scripts": {
"build": "tsc && npm run copy-schemas",
"copy-schemas": "cpx src/**/*.graphql dist/src",
"build": "tsc",
"copy-schemas": "cpx src/**/*.graphql dist",
"clean": "modclean --no-progress --run --path .",
"commit": "npx git-cz",
"lint": "xo --verbose",
@@ -23,7 +23,8 @@
"release": "standard-version"
},
"files": [
"dist"
"dist",
"index.js"
],
"dependencies": {
"@gridplus/docker-events": "github:OmgImAlexis/docker-events",
@@ -64,6 +65,7 @@
"husky": "^4.0.4",
"modclean": "^3.0.0-beta.1",
"node-env-run": "^3.0.2",
"source-map-support": "0.5.16",
"standard-version": "^7.0.1",
"typescript": "3.7.5",
"xo": "^0.25.3"