Skip to content

Commit

Permalink
Merge pull request #1126 from automatisch/optimize-last-execution
Browse files Browse the repository at this point in the history
refactor: Optimize fetching last execution step
  • Loading branch information
farukaydin committed Jun 5, 2023
2 parents 9f759d7 + 6a92cfc commit 34e95f1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
}
},
});
}
},
Expand All @@ -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}`);
},
});
10 changes: 6 additions & 4 deletions packages/backend/src/apps/twilio/triggers/receive-sms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineTrigger({
{
name: 'parameters.valueType',
value: 'sid',
}
},
],
},
},
Expand All @@ -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: '',
}
},
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
}
},
});
}
},
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/helpers/global-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export type IGlobalVariable = {
testRun: boolean;
exit: () => void;
};
lastExecutionStep?: IExecutionStep;
getLastExecutionStep?: () => Promise<IExecutionStep>;
webhookUrl?: string;
triggerOutput?: ITriggerOutput;
actionOutput?: IActionOutput;
Expand Down

0 comments on commit 34e95f1

Please sign in to comment.