fix(plugin-workflow): fix customized job status (#1484)
This commit is contained in:
parent
a18918576b
commit
a19a18b1f7
@ -205,7 +205,7 @@ export default class Processor {
|
||||
}
|
||||
|
||||
async exit(job: JobModel | null) {
|
||||
const status = job ? (<typeof Processor>this.constructor).StatusMap[job.status] : EXECUTION_STATUS.RESOLVED;
|
||||
const status = job ? (<typeof Processor>this.constructor).StatusMap[job.status] ?? Math.sign(job.status) : EXECUTION_STATUS.RESOLVED;
|
||||
await this.execution.update({ status }, { transaction: this.transaction });
|
||||
return null;
|
||||
}
|
||||
|
@ -129,6 +129,42 @@ describe('workflow > Processor', () => {
|
||||
expect(status).toEqual(JOB_STATUS.ERROR);
|
||||
expect(result.message).toBe('definite error');
|
||||
});
|
||||
|
||||
it('workflow with customized success node', async () => {
|
||||
await workflow.createNode({
|
||||
type: 'customizedSuccess'
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: { title: 't1' } });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||
|
||||
const jobs = await execution.getJobs();
|
||||
expect(jobs.length).toEqual(1);
|
||||
const { status, result } = jobs[0].get();
|
||||
expect(status).toEqual(100);
|
||||
});
|
||||
|
||||
it('workflow with customized error node', async () => {
|
||||
await workflow.createNode({
|
||||
type: 'customizedError'
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: { title: 't1' } });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.FAILED);
|
||||
|
||||
const jobs = await execution.getJobs();
|
||||
expect(jobs.length).toEqual(1);
|
||||
const { status, result } = jobs[0].get();
|
||||
expect(status).toEqual(-100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('manual nodes', () => {
|
||||
|
@ -23,7 +23,7 @@ export async function getApp({ manual, ...options }: MockAppOptions = {}): Promi
|
||||
name: 'workflow',
|
||||
instructions: {
|
||||
echo: {
|
||||
run(node, { result }, execution) {
|
||||
run(node, { result }, processor) {
|
||||
return {
|
||||
status: JOB_STATUS.RESOLVED,
|
||||
result,
|
||||
@ -32,21 +32,37 @@ export async function getApp({ manual, ...options }: MockAppOptions = {}): Promi
|
||||
},
|
||||
|
||||
error: {
|
||||
run(node, input, execution) {
|
||||
run(node, input, processor) {
|
||||
throw new Error('definite error');
|
||||
},
|
||||
},
|
||||
|
||||
'prompt->error': {
|
||||
run(node, input, execution) {
|
||||
run(node, input, processor) {
|
||||
return {
|
||||
status: JOB_STATUS.PENDING,
|
||||
};
|
||||
},
|
||||
resume(node, input, execution) {
|
||||
resume(node, input, processor) {
|
||||
throw new Error('input failed');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
customizedSuccess: {
|
||||
run(node, input, processor) {
|
||||
return {
|
||||
status: 100
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
customizedError: {
|
||||
run(node, input, processor) {
|
||||
return {
|
||||
status: -100
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
functions: {
|
||||
no1: () => 1
|
||||
|
Loading…
Reference in New Issue
Block a user