feat: Add delay application along with delay for action

This commit is contained in:
Faruk AYDIN
2022-12-15 01:01:30 +03:00
parent 8036d20bf9
commit 469050914b
7 changed files with 122 additions and 1 deletions

View File

@@ -4,7 +4,13 @@ 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';
import {
REMOVE_AFTER_30_DAYS_OR_150_JOBS,
REMOVE_AFTER_7_DAYS_OR_50_JOBS,
} from '../helpers/remove-job-configuration';
import delayAsMilliseconds, {
TDelayForUnit,
} from '../helpers/delay-as-milliseconds';
type JobData = {
flowId: string;
@@ -12,6 +18,8 @@ type JobData = {
stepId: string;
};
const DEFAULT_DELAY_DURATION = 0;
export const worker = new Worker(
'action',
async (job) => {
@@ -35,6 +43,18 @@ export const worker = new Worker(
const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
delay: DEFAULT_DELAY_DURATION,
};
const stepApp = await step.getApp();
if (stepApp.key === 'delay') {
const { delayForUnit, delayForValue } = step.parameters;
jobOptions.delay = delayAsMilliseconds(
delayForUnit as TDelayForUnit,
Number(delayForValue)
);
}
await actionQueue.add(jobName, jobPayload, jobOptions);