Skip to content

Commit 4eadcae

Browse files
Merge pull request #178 from topcoder-platform/PM-3080
PM-3080 delete aiWorkflowRun data before deleting a submission
2 parents bc0b2be + d5b55a4 commit 4eadcae

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.circleci/config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ workflows:
7474
branches:
7575
only:
7676
- develop
77-
- feat/ai-workflows
78-
- pm-1955_2
79-
- re-try-failed-jobs
80-
- pm-2539
81-
- pm-2177_fixes
8277

8378

8479
- 'build-prod':
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- DropForeignKey
2+
ALTER TABLE "aiWorkflowRunItem" DROP CONSTRAINT "aiWorkflowRunItem_workflowRunId_fkey";
3+
4+
-- DropForeignKey
5+
ALTER TABLE "aiWorkflowRunItemComment" DROP CONSTRAINT "aiWorkflowRunItemComment_workflowRunItemId_fkey";
6+
7+
-- AddForeignKey
8+
ALTER TABLE "aiWorkflowRunItem" ADD CONSTRAINT "aiWorkflowRunItem_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "aiWorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE;
9+
10+
-- AddForeignKey
11+
ALTER TABLE "aiWorkflowRunItemComment" ADD CONSTRAINT "aiWorkflowRunItemComment_workflowRunItemId_fkey" FOREIGN KEY ("workflowRunItemId") REFERENCES "aiWorkflowRunItem"("id") ON DELETE CASCADE ON UPDATE CASCADE;

src/api/submission/submission.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,34 @@ export class SubmissionService {
22872287
});
22882288
}
22892289
}
2290+
const TERMINAL_STATUSES = [
2291+
'COMPLETED',
2292+
'FAILURE',
2293+
'CANCELLED',
2294+
'SUCCESS',
2295+
];
2296+
2297+
const runs = await this.prisma.aiWorkflowRun.findMany({
2298+
where: { submissionId: id },
2299+
select: { id: true, status: true },
2300+
});
2301+
2302+
if (runs.length > 0) {
2303+
const nonTerminal = runs.filter(
2304+
(r) => !TERMINAL_STATUSES.includes(r.status),
2305+
);
2306+
2307+
if (nonTerminal.length > 0) {
2308+
throw new Error(
2309+
`Cannot delete submission: ${nonTerminal.length} workflow run(s) still active.`,
2310+
);
2311+
}
2312+
2313+
await this.prisma.aiWorkflowRun.deleteMany({
2314+
where: { submissionId: id },
2315+
});
2316+
}
2317+
22902318
await this.prisma.submission.delete({
22912319
where: { id },
22922320
});

0 commit comments

Comments
 (0)