diff --git a/packages/app-backend/src/coverage/services/trigger-agg-coverage.service.ts b/packages/app-backend/src/coverage/services/trigger-agg-coverage.service.ts index d61681e0..caa001d2 100644 --- a/packages/app-backend/src/coverage/services/trigger-agg-coverage.service.ts +++ b/packages/app-backend/src/coverage/services/trigger-agg-coverage.service.ts @@ -9,6 +9,15 @@ export class TriggerAggCoverageService { async invoke(params) { let { report_id } = params; const { pkgId } = params; + const tasks = await this.prisma.task + .findMany({ + where: { + type: 'coverageagg', + }, + }) + .then((res) => + res.filter((i: any) => i.data.report_id === params.report_id), + ); if (pkgId) { try { report_id = await axios @@ -39,24 +48,30 @@ export class TriggerAggCoverageService { code: 0, }; } - - await this.prisma.task.create({ - data: { - name: `Coverage Agg Task ${report_id}`, - status: 'notstarted', - type: 'coverageagg', + if (tasks.length > 0) { + return { + msg: '该报告已聚合', + data: [], + code: -1, + }; + } else { + await this.prisma.task.create({ data: { - report_id: report_id, + name: `Coverage Agg Task ${report_id}`, + status: 'notstarted', + type: 'coverageagg', + data: { + report_id: report_id, + }, + result: {}, + logs: [], }, - result: {}, - logs: [], - }, - }); - - return { - msg: '聚合中', - data: [], - code: 1, - }; + }); + return { + msg: '聚合中', + data: [], + code: 1, + }; + } } }