feat(queue): auto clean up complete and fail jobs

This commit is contained in:
Ali BARIN
2022-11-27 19:25:10 +01:00
parent 4240849a2a
commit 2e391cc651
5 changed files with 36 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import logger from '../helpers/logger';
import Step from '../models/step';
import actionQueue from '../queues/action';
import { processAction } from '../services/action';
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../helpers/remove-job-configuration';
type JobData = {
flowId: string;
@@ -31,7 +32,12 @@ export const worker = new Worker(
stepId: nextStep.id,
};
await actionQueue.add(jobName, jobPayload);
const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
}
await actionQueue.add(jobName, jobPayload, jobOptions);
},
{ connection: redisConfig }
);
@@ -42,7 +48,7 @@ worker.on('completed', (job) => {
worker.on('failed', (job, err) => {
logger.info(
`JOB ID: ${job.id} - FLOW ID: ${job.data.flowId} has failed22 to start with ${err.message}`
`JOB ID: ${job.id} - FLOW ID: ${job.data.flowId} has failed to start with ${err.message}`
);
});