refactor: Remove dedupe strategies, use only dedupe list
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
ITriggerItem,
|
ITriggerItem,
|
||||||
IActionItem,
|
IActionItem,
|
||||||
} from '@automatisch/types';
|
} from '@automatisch/types';
|
||||||
|
import EarlyExitError from '../errors/early-exit';
|
||||||
|
|
||||||
type GlobalVariableOptions = {
|
type GlobalVariableOptions = {
|
||||||
connection?: Connection;
|
connection?: Connection;
|
||||||
@@ -25,9 +26,7 @@ const globalVariable = async (
|
|||||||
): Promise<IGlobalVariable> => {
|
): Promise<IGlobalVariable> => {
|
||||||
const { connection, app, flow, step, execution, testRun = false } = options;
|
const { connection, app, flow, step, execution, testRun = false } = options;
|
||||||
|
|
||||||
const lastInternalId = await flow?.lastInternalId();
|
const lastInternalId = testRun ? undefined : await flow?.lastInternalId();
|
||||||
|
|
||||||
const trigger = await step?.getTriggerCommand();
|
|
||||||
const nextStep = await step?.getNextStep();
|
const nextStep = await step?.getNextStep();
|
||||||
|
|
||||||
const $: IGlobalVariable = {
|
const $: IGlobalVariable = {
|
||||||
@@ -75,6 +74,13 @@ const globalVariable = async (
|
|||||||
},
|
},
|
||||||
pushTriggerItem: (triggerItem: ITriggerItem) => {
|
pushTriggerItem: (triggerItem: ITriggerItem) => {
|
||||||
$.triggerOutput.data.push(triggerItem);
|
$.triggerOutput.data.push(triggerItem);
|
||||||
|
|
||||||
|
if (
|
||||||
|
$.execution.testRun ||
|
||||||
|
isAlreadyProcessed(triggerItem.meta.internalId)
|
||||||
|
) {
|
||||||
|
throw new EarlyExitError();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setActionItem: (actionItem: IActionItem) => {
|
setActionItem: (actionItem: IActionItem) => {
|
||||||
$.actionOutput.data = actionItem;
|
$.actionOutput.data = actionItem;
|
||||||
@@ -87,27 +93,12 @@ const globalVariable = async (
|
|||||||
beforeRequest: app.beforeRequest,
|
beforeRequest: app.beforeRequest,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (trigger) {
|
const lastInternalIds =
|
||||||
if (trigger.dedupeStrategy === 'unique') {
|
testRun || (flow && step.isAction) ? [] : await flow?.lastInternalIds();
|
||||||
const lastInternalIds = testRun ? [] : await flow?.lastInternalIds();
|
|
||||||
|
|
||||||
const isAlreadyProcessed = (internalId: string) => {
|
const isAlreadyProcessed = (internalId: string) => {
|
||||||
if (testRun) return false;
|
return lastInternalIds?.includes(internalId);
|
||||||
|
};
|
||||||
return lastInternalIds?.includes(internalId);
|
|
||||||
};
|
|
||||||
|
|
||||||
$.flow.isAlreadyProcessed = isAlreadyProcessed;
|
|
||||||
} else if (trigger.dedupeStrategy === 'greatest') {
|
|
||||||
const isAlreadyProcessed = (internalId: string) => {
|
|
||||||
if (testRun) return false;
|
|
||||||
|
|
||||||
return Number(internalId) <= Number($.flow.lastInternalId);
|
|
||||||
};
|
|
||||||
|
|
||||||
$.flow.isAlreadyProcessed = isAlreadyProcessed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $;
|
return $;
|
||||||
};
|
};
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import Flow from '../models/flow';
|
import Flow from '../models/flow';
|
||||||
import globalVariable from '../helpers/global-variable';
|
import globalVariable from '../helpers/global-variable';
|
||||||
|
import EarlyExitError from '../errors/early-exit';
|
||||||
|
|
||||||
type ProcessFlowOptions = {
|
type ProcessFlowOptions = {
|
||||||
flowId: string;
|
flowId: string;
|
||||||
@@ -23,13 +24,15 @@ export const processFlow = async (options: ProcessFlowOptions) => {
|
|||||||
try {
|
try {
|
||||||
await triggerCommand.run($);
|
await triggerCommand.run($);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error?.response?.httpError) {
|
if (error instanceof EarlyExitError === false) {
|
||||||
$.triggerOutput.error = error.response.httpError;
|
if (error?.response?.httpError) {
|
||||||
} else {
|
$.triggerOutput.error = error.response.httpError;
|
||||||
try {
|
} else {
|
||||||
$.triggerOutput.error = JSON.parse(error.message);
|
try {
|
||||||
} catch {
|
$.triggerOutput.error = JSON.parse(error.message);
|
||||||
$.triggerOutput.error = { error: error.message };
|
} catch {
|
||||||
|
$.triggerOutput.error = { error: error.message };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user