refactor: Optimize fetching last execution step

This commit is contained in:
Faruk AYDIN
2023-06-05 23:00:35 +02:00
parent 9f759d70b6
commit 6a92cfc573
5 changed files with 23 additions and 21 deletions

View File

@@ -20,12 +20,14 @@ export default defineTrigger({
],
async testRun($) {
if (!isEmpty($.lastExecutionStep?.dataOut)) {
const lastExecutionStep = await $.getLastExecutionStep();
if (!isEmpty(lastExecutionStep?.dataOut)) {
$.pushTriggerItem({
raw: $.lastExecutionStep.dataOut,
raw: lastExecutionStep.dataOut,
meta: {
internalId: '',
}
},
});
}
},
@@ -35,20 +37,15 @@ export default defineTrigger({
name: $.flow.id,
type: 'POST',
url: $.webhookUrl,
filters: [$.step.parameters.filters]
filters: [$.step.parameters.filters],
};
const { data } = await $.http.post(
`/v2/public/api/webhooks`,
payload
);
const { data } = await $.http.post(`/v2/public/api/webhooks`, payload);
await $.flow.setRemoteWebhookId(data.id);
},
async unregisterHook($) {
await $.http.delete(
`/v2/public/api/webhooks/${$.flow.remoteWebhookId}`
);
await $.http.delete(`/v2/public/api/webhooks/${$.flow.remoteWebhookId}`);
},
});

View File

@@ -28,7 +28,7 @@ export default defineTrigger({
{
name: 'parameters.valueType',
value: 'sid',
}
},
],
},
},
@@ -37,12 +37,14 @@ export default defineTrigger({
async testRun($) {
await fetchMessages($);
if (!isEmpty($.lastExecutionStep?.dataOut)) {
const lastExecutionStep = await $.getLastExecutionStep();
if (!isEmpty(lastExecutionStep?.dataOut)) {
$.pushTriggerItem({
raw: $.lastExecutionStep.dataOut,
raw: lastExecutionStep.dataOut,
meta: {
internalId: '',
}
},
});
}
},

View File

@@ -8,12 +8,14 @@ export default defineTrigger({
description: 'Triggers when the webhook receives a request.',
async testRun($) {
if (!isEmpty($.lastExecutionStep?.dataOut)) {
const lastExecutionStep = await $.getLastExecutionStep();
if (!isEmpty(lastExecutionStep?.dataOut)) {
$.pushTriggerItem({
raw: $.lastExecutionStep.dataOut,
raw: lastExecutionStep.dataOut,
meta: {
internalId: '',
}
},
});
}
},

View File

@@ -80,9 +80,10 @@ const globalVariable = async (
testRun,
exit: () => {
throw new EarlyExitError();
}
},
lastExecutionStep: (await step?.getLastExecutionStep())?.toJSON(),
},
getLastExecutionStep: async () =>
(await step?.getLastExecutionStep())?.toJSON(),
triggerOutput: {
data: [],
},

View File

@@ -331,7 +331,7 @@ export type IGlobalVariable = {
testRun: boolean;
exit: () => void;
};
lastExecutionStep?: IExecutionStep;
getLastExecutionStep?: () => Promise<IExecutionStep>;
webhookUrl?: string;
triggerOutput?: ITriggerOutput;
actionOutput?: IActionOutput;