Skip to content

Commit

Permalink
Rename filter and invert condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Michalski committed May 19, 2021
1 parent 3aca42f commit cb7a89a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 5 additions & 5 deletions clean_failed_job_stacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sendToSlack = require('./utils/slack')(process.env.SLACK_WEBHOOK_URL, proc

const sumArray = require('./utils/sumArray')
const getFailedQueues = require('./utils/getFailedQueues')
const getAttemptedJobs = require('./utils/jobsExceedingAttemptsFilter')
const getJobsBelowAttemptLimit = require('./utils/jobsNotExceedingAttemptsFilter')

console.log(`${new Date().toISOString()} - Checking for failed jobs in ${queueNames.join(', ')} queues`)

Expand All @@ -17,15 +17,15 @@ getFailedQueues(queueNames)
.then(async queues => {
const retriedJobCountsForEachQueue = await Promise.all(
queues.map(async queue => {
const failedJobs = getAttemptedJobs(await queue.getFailed())
const failedJobsToRetry = getJobsBelowAttemptLimit(await queue.getFailed())

if (!failedJobs.length) {
if (!failedJobsToRetry.length) {
return queue.close().then(() => 0)
}

const failedCount = failedJobs.length
const failedCount = failedJobsToRetry.length
const retriedJobs = await pMap(
failedJobs,
failedJobsToRetry,
async job => {
const { id, data, opts } = job
opts.jobId = id
Expand Down
3 changes: 0 additions & 3 deletions utils/jobsExceedingAttemptsFilter.js

This file was deleted.

10 changes: 10 additions & 0 deletions utils/jobsNotExceedingAttemptsFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const MAX_FAILED_COUNT = Number.parseInt(process.env.MAX_FAILED_COUNT)

module.exports = jobs => jobs.filter(job => {
if (job && typeof job === 'object') {
const max = (MAX_FAILED_COUNT || Number.parseInt(job.opts.attempts) || 100)
return job.attemptsMade < max
}
return false
})

0 comments on commit cb7a89a

Please sign in to comment.