feat(engine): Add progress callAction — needs tests.

This commit is contained in:
Gervwyk 2022-03-04 16:45:53 +02:00
parent 2351f10630
commit 771961ca1d
2 changed files with 19 additions and 6 deletions

View File

@ -44,7 +44,7 @@ class Actions {
}
}
async callActionLoop({ actions, arrayIndices, block, event, responses }) {
async callActionLoop({ actions, arrayIndices, block, event, progress, responses }) {
for (const [index, action] of actions.entries()) {
try {
if (action.async === true) {
@ -54,6 +54,7 @@ class Actions {
block,
event,
index,
progress,
responses,
});
} else {
@ -63,6 +64,7 @@ class Actions {
block,
event,
index,
progress,
responses,
});
responses[action.id] = response;
@ -77,15 +79,22 @@ class Actions {
}
}
async callActions({ actions, arrayIndices, block, catchActions, event, eventName }) {
async callActions({ actions, arrayIndices, block, catchActions, event, eventName, progress }) {
const startTimestamp = new Date();
const responses = {};
try {
await this.callActionLoop({ actions, arrayIndices, block, event, responses });
await this.callActionLoop({ actions, arrayIndices, block, event, responses, progress });
} catch (error) {
console.error(error);
try {
await this.callActionLoop({ actions: catchActions, arrayIndices, block, event, responses });
await this.callActionLoop({
actions: catchActions,
arrayIndices,
block,
event,
responses,
progress,
});
} catch (errorCatch) {
console.error(errorCatch);
return {
@ -125,7 +134,7 @@ class Actions {
};
}
async callAction({ action, arrayIndices, block, event, index, responses }) {
async callAction({ action, arrayIndices, block, event, index, progress, responses }) {
if (!this.actions[action.type]) {
throw {
error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
@ -167,6 +176,9 @@ class Actions {
params: parsedAction.params,
window: this.context._internal.lowdefy._internal.window,
});
if (progress) {
progress();
}
} catch (error) {
responses[action.id] = { error, index, type: action.type };
const { output: parsedMessages, errors: parserErrors } = this.context._internal.parser.parse({

View File

@ -53,7 +53,7 @@ class Events {
this.events[name] = this.initEvent(actions);
}
async triggerEvent({ name, event }) {
async triggerEvent({ name, event, progress }) {
const eventDescription = this.events[name];
let result = {
blockId: this.block.blockId,
@ -81,6 +81,7 @@ class Events {
catchActions: eventDescription.catchActions,
event,
eventName: name,
progress,
});
eventDescription.history.unshift(res);
this.context.eventLog.unshift(res);