mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-11 14:20:07 +08:00
feat(engine): Add progress callAction — needs tests.
This commit is contained in:
parent
2351f10630
commit
771961ca1d
@ -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({
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user