Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
✨ Now handles shutdown gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
davidahouse committed Nov 12, 2019
1 parent 6869a9f commit 5da2030
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions bin/stampede-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ if (
process.exit(1);
}

let workerQueue = null;
let responseQueue = null;
let heartbeatQueue = null;

if (conf.taskTestFile == null) {
const workerQueue = new Queue("stampede-" + conf.taskQueue, redisConfig);
const responseQueue = new Queue(
"stampede-" + conf.responseQueue,
redisConfig
);
const heartbeatQueue =
workerQueue = new Queue("stampede-" + conf.taskQueue, redisConfig);
responseQueue = new Queue("stampede-" + conf.responseQueue, redisConfig);
heartbeatQueue =
conf.heartbeatQueue != null
? new Queue("stampede-" + conf.heartbeatQueue, redisConfig)
: null;
Expand All @@ -117,6 +118,24 @@ if (conf.taskTestFile == null) {
handleTask(task, responseTestFile);
}

/**
* Handle shutdown gracefully
*/
process.on("SIGINT", function() {
gracefulShutdown();
});

/**
* gracefulShutdown
*/
async function gracefulShutdown() {
console.log("Closing queues");
await workerQueue.close();
await responseQueue.close();
await heartbeatQueue.close();
process.exit(0);
}

/**
* Handle an incoming task
* @param {*} task
Expand Down

0 comments on commit 5da2030

Please sign in to comment.