Skip to content

Commit

Permalink
Added env variable MAX_FAILED_COUNT and set sane default value of 100.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Michalski committed Jul 23, 2020
1 parent d5d0488 commit 94d9c36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions retry_failed_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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++
Expand Down

0 comments on commit 94d9c36

Please sign in to comment.