Skip to content

Commit

Permalink
worker: Add graceful shutdown
Browse files Browse the repository at this point in the history
The graceful shutdown mechanism is only available for clustered
isntallations (e.g. devMode = true). This patch adds this option for
single core/signle thread processes as well.
  • Loading branch information
Kostas Pelelis committed Dec 14, 2018
1 parent 3f7b898 commit ed12c9b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ const worker = (app, config, onServer, workerId) => {
// server.closing
attachEndpoint(app, config, () => server && server.closing);

function registerSignalHandler(sig) {
process.on(sig, () => {
logger.info(`Hypernova worker got ${sig}. Going down`);
server.shutDownSequence();
});
}

// Gracefully shutdown the worker when not running in a cluster (devMode = true)
if(config.devMode) {
['SIGTERM', 'SIGINT'].map(registerSignalHandler);
}

// ===== initialize server's nuts and bolts =================================
server = initServer(app, config, () => {
if (process.send) {
Expand Down

0 comments on commit ed12c9b

Please sign in to comment.