fix: Implement graceful shutdown for worker and queue scheduler

This commit is contained in:
Faruk AYDIN
2022-05-13 10:22:58 +02:00
parent cc1892a5cf
commit 57186bf85d
2 changed files with 9 additions and 1 deletions

View File

@@ -10,7 +10,11 @@ const redisConnection = {
};
const processorQueue = new Queue('processor', redisConnection);
new QueueScheduler('processor', redisConnection);
const queueScheduler = new QueueScheduler('processor', redisConnection);
process.on('SIGTERM', async () => {
await queueScheduler.close();
});
processorQueue.on('error', (err) => {
if ((err as any).code === CONNECTION_REFUSED) {

View File

@@ -24,3 +24,7 @@ worker.on('failed', (job, err) => {
`JOB ID: ${job.id} - FLOW ID: ${job.data.flowId} has failed with ${err.message}`
);
});
process.on('SIGTERM', async () => {
await worker.close();
});