refactor: Use trigger queue for webhook handler

This commit is contained in:
Faruk AYDIN
2023-10-09 12:05:45 +02:00
parent 4c66cc1e33
commit d877f5c764

View File

@@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty';
import Flow from '../models/flow'; import Flow from '../models/flow';
import { processTrigger } from '../services/trigger'; import { processTrigger } from '../services/trigger';
import actionQueue from '../queues/action'; import triggerQueue from '../queues/trigger';
import globalVariable from './global-variable'; import globalVariable from './global-variable';
import QuotaExceededError from '../errors/quote-exceeded'; import QuotaExceededError from '../errors/quote-exceeded';
import { import {
@@ -59,32 +59,31 @@ export default async (
} }
for (const triggerItem of reversedTriggerItems) { for (const triggerItem of reversedTriggerItems) {
const { executionId } = await processTrigger({ if (testRun) {
await processTrigger({
flowId, flowId,
stepId: triggerStep.id, stepId: triggerStep.id,
triggerItem, triggerItem,
testRun, testRun,
}); });
if (testRun) {
continue; continue;
} }
const nextStep = await triggerStep.getNextStep(); const jobName = `${triggerStep.id}-${triggerItem.meta.internalId}`;
const jobName = `${executionId}-${nextStep.id}`;
const jobPayload = {
flowId,
executionId,
stepId: nextStep.id,
};
const jobOptions = { const jobOptions = {
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS, removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS, removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
}; };
await actionQueue.add(jobName, jobPayload, jobOptions); const jobPayload = {
flowId,
stepId: triggerStep.id,
triggerItem,
};
await triggerQueue.add(jobName, jobPayload, jobOptions);
} }
return response.status(204); return response.status(204);