fix(plugin-workflow): fix end logic when success (#3453)

This commit is contained in:
Junyi 2024-01-29 14:04:37 +08:00 committed by GitHub
parent 2fc1604d78
commit ad065431fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 10 deletions

View File

@ -200,8 +200,7 @@ const useStyles = createStyles(({ css, token }) => {
align-items: center;
justify-content: center;
width: 0;
height: 4em;
padding: 1em 0;
height: 6em;
border-left: 1px dashed ${token.colorBgLayout};
.anticon {

View File

@ -35,12 +35,20 @@ describe('workflow > instructions > end', () => {
},
});
const n2 = await workflow.createNode({
type: 'echo',
upstreamId: n1.id,
});
await n1.setDownstream(n2);
await plugin.trigger(workflow, {});
const [execution] = await workflow.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
const [job] = await execution.getJobs();
expect(job.status).toBe(JOB_STATUS.RESOLVED);
const jobs = await execution.getJobs();
expect(jobs.length).toBe(1);
expect(jobs[0].status).toBe(JOB_STATUS.RESOLVED);
});
it('failed', async () => {
@ -51,12 +59,20 @@ describe('workflow > instructions > end', () => {
},
});
const n2 = await workflow.createNode({
type: 'echo',
upstreamId: n1.id,
});
await n1.setDownstream(n2);
await plugin.trigger(workflow, {});
const [execution] = await workflow.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.FAILED);
const [job] = await execution.getJobs();
expect(job.status).toBe(JOB_STATUS.FAILED);
const jobs = await execution.getJobs();
expect(jobs.length).toBe(1);
expect(jobs[0].status).toBe(JOB_STATUS.FAILED);
});
});
});

View File

@ -9,9 +9,14 @@ interface Config {
export default class extends Instruction {
async run(node: FlowNodeModel, prevJob, processor: Processor) {
const { endStatus } = <Config>node.config;
return {
status: endStatus ?? JOB_STATUS.RESOLVED,
};
const { endStatus = JOB_STATUS.RESOLVED } = <Config>node.config;
await processor.saveJob({
status: endStatus,
nodeId: node.id,
nodeKey: node.key,
upstreamId: prevJob?.id ?? null,
});
return processor.exit(endStatus);
}
}