feat(webhook): process trigger in controller
This commit is contained in:
@@ -3,8 +3,10 @@ import bcrypt from 'bcrypt';
|
|||||||
import { IRequest, ITriggerItem } from '@automatisch/types';
|
import { IRequest, ITriggerItem } from '@automatisch/types';
|
||||||
|
|
||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import triggerQueue from '../../queues/trigger';
|
import { processTrigger } from '../../services/trigger';
|
||||||
|
import actionQueue from '../../queues/action';
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
|
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../../helpers/remove-job-configuration';
|
||||||
|
|
||||||
export default async (request: IRequest, response: Response) => {
|
export default async (request: IRequest, response: Response) => {
|
||||||
const flow = await Flow.query()
|
const flow = await Flow.query()
|
||||||
@@ -47,15 +49,27 @@ export default async (request: IRequest, response: Response) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const jobName = `${triggerStep.id}-${triggerItem.meta.internalId}`;
|
const { flowId, executionId } = await processTrigger({
|
||||||
|
|
||||||
const jobPayload = {
|
|
||||||
flowId: flow.id,
|
flowId: flow.id,
|
||||||
stepId: triggerStep.id,
|
stepId: triggerStep.id,
|
||||||
triggerItem,
|
triggerItem,
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextStep = await triggerStep.getNextStep();
|
||||||
|
const jobName = `${executionId}-${nextStep.id}`;
|
||||||
|
|
||||||
|
const jobPayload = {
|
||||||
|
flowId,
|
||||||
|
executionId,
|
||||||
|
stepId: nextStep.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
await triggerQueue.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);
|
||||||
|
|
||||||
return response.sendStatus(200);
|
return response.sendStatus(200);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user