Skip to content

Commit 0a5aa2d

Browse files
committed
Fix slow job retries by optimizing how errored tasks are deleted
1 parent 4a1a5b2 commit 0a5aa2d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

apps/webapp/app/services/runs/continueRun.server.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export class ContinueRunService {
3232
throw new Error("Run is not resumable");
3333
}
3434

35+
// Delete any tasks that are errored
36+
const erroredTasks = await tx.task.findMany({
37+
where: {
38+
runId: runId,
39+
status: "ERRORED",
40+
},
41+
});
42+
3543
await tx.jobRun.update({
3644
where: { id: runId },
3745
data: {
@@ -45,17 +53,15 @@ export class ContinueRunService {
4553
},
4654
});
4755

48-
// Delete any tasks that are errored
49-
await tx.task.deleteMany({
50-
where: {
51-
runId: runId,
52-
status: "ERRORED",
53-
},
54-
});
56+
for (const task of erroredTasks) {
57+
await tx.task.delete({
58+
where: { id: task.id },
59+
});
60+
}
5561

5662
await ResumeRunService.enqueue(run, tx);
5763
},
58-
{ timeout: 10000 }
64+
{ timeout: 30_000 }
5965
);
6066
}
6167
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- DropForeignKey
2+
ALTER TABLE "JobRunExecution" DROP CONSTRAINT "JobRunExecution_resumeTaskId_fkey";
3+
4+
-- AddForeignKey
5+
ALTER TABLE "JobRunExecution" ADD CONSTRAINT "JobRunExecution_resumeTaskId_fkey" FOREIGN KEY ("resumeTaskId") REFERENCES "Task"("id") ON DELETE SET NULL ON UPDATE CASCADE;

packages/database/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ model JobRunExecution {
991991
reason JobRunExecutionReason @default(EXECUTE_JOB)
992992
status JobRunExecutionStatus @default(PENDING)
993993
994-
resumeTask Task? @relation(fields: [resumeTaskId], references: [id], onDelete: Cascade, onUpdate: Cascade)
994+
resumeTask Task? @relation(fields: [resumeTaskId], references: [id], onDelete: SetNull, onUpdate: Cascade)
995995
resumeTaskId String?
996996
997997
graphileJobId String?

0 commit comments

Comments
 (0)