fix(plugin-workflow): fix events in prepare (#1325)

This commit is contained in:
Junyi 2023-01-04 18:26:44 +08:00 committed by GitHub
parent fb8a4de8cc
commit 8943dabc4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -158,7 +158,11 @@ export default class WorkflowPlugin extends Plugin {
} }
private prepare = async () => { private prepare = async () => {
const [workflow, context, options] = this.events[0]; const event = this.events.shift();
if (!event) {
return;
}
const [workflow, context, options] = event;
if (options.context?.executionId) { if (options.context?.executionId) {
// NOTE: no transaction here for read-uncommitted execution // NOTE: no transaction here for read-uncommitted execution
@ -213,8 +217,6 @@ export default class WorkflowPlugin extends Plugin {
this.pending.push([execution]); this.pending.push([execution]);
} }
this.events.shift();
if (this.events.length) { if (this.events.length) {
await this.prepare(); await this.prepare();
} else { } else {

View File

@ -215,6 +215,17 @@ describe('workflow > Plugin', () => {
const [execution] = await workflow.getExecutions(); const [execution] = await workflow.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED); expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
// NOTE: second trigger to ensure no skipped event
const p3 = await PostRepo.create({ values: { title: 't2' } });
await sleep(500);
const posts2 = await PostRepo.find();
expect(posts2.length).toBe(4);
const [execution2] = await workflow.getExecutions({ order: [['createdAt', 'DESC']] });
expect(execution2.status).toBe(EXECUTION_STATUS.RESOLVED);
}); });
}); });