From 94d9c3646bf87062d31f7ff0c322fedd7f6bc309 Mon Sep 17 00:00:00 2001 From: Robert Michalski Date: Thu, 23 Jul 2020 10:32:31 +0200 Subject: [PATCH] Added env variable MAX_FAILED_COUNT and set sane default value of 100. --- .env.example | 2 ++ retry_failed_jobs.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/.env.example b/.env.example index dd636cc..54bb9cf 100644 --- a/.env.example +++ b/.env.example @@ -7,5 +7,7 @@ REDIS_DATABASE=0 #REDIS_PASS= #REDIS_TLS=true +MAX_FAILED_COUNT=100 + SLACK_WEBHOOK_URL=https://hooks.slack.com/services/... SLACK_CHANNEL="#my-channel" diff --git a/retry_failed_jobs.js b/retry_failed_jobs.js index e4a749e..5cd546c 100644 --- a/retry_failed_jobs.js +++ b/retry_failed_jobs.js @@ -12,6 +12,7 @@ const REDIS_HOST = process.env.REDIS_HOST || '127.0.0.1' const REDIS_DATABASE = Number.parseInt(process.env.REDIS_DATABASE) || 0 const REDIS_PASS = process.env.REDIS_PASS const REDIS_TLS = process.env.REDIS_TLS && `${process.env.REDIS_TLS}` === 'true' +const MAX_FAILED_COUNT = Number.parseInt(process.env.MAX_FAILED_COUNT) || 100 const REDIS_CONFIG = { redis: { @@ -48,6 +49,9 @@ forEach(args, async (name, index) => { const jobs = await queue.getFailed() const retriedJobCount = await reduce(jobs, async (count, job) => { + if (job.attemptsMade > MAX_FAILED_COUNT) { + return result + } try { await job.retry() count++