From 14f2b3ad1145595190ec515b3d8b23603d01281c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Jul 2018 18:49:54 +0200 Subject: [PATCH] Graceful job queue shutdown --- server.ts | 6 ++++++ server/lib/job-queue/job-queue.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/server.ts b/server.ts index efbfd3c97..0e6f787a6 100644 --- a/server.ts +++ b/server.ts @@ -195,4 +195,10 @@ async function startApplication () { logger.info('Server listening on %s:%d', hostname, port) logger.info('Web server: %s', CONFIG.WEBSERVER.URL) }) + + process.on('exit', () => { + JobQueue.Instance.terminate() + }) + + process.on('SIGINT', () => process.exit(0)) } diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index b018d0e8a..157c57ba9 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -83,6 +83,13 @@ class JobQueue { } } + terminate () { + for (const queueName of Object.keys(this.queues)) { + const queue = this.queues[queueName] + queue.close() + } + } + createJob (obj: CreateJobArgument) { const queue = this.queues[obj.type] if (queue === undefined) { -- 2.41.0