Skip to content

Commit bcafd44

Browse files
committed
CompleteAttemptService system failure switched to FinalizeTaskRunService
1 parent 4a438f6 commit bcafd44

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

apps/webapp/app/v3/services/completeAttempt.server.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TaskRun } from "@trigger.dev/database";
2323
import { PerformTaskAttemptAlertsService } from "./alerts/performTaskAttemptAlerts.server";
2424
import { RetryAttemptService } from "./retryAttempt.server";
2525
import { isFinalAttemptStatus, isFinalRunStatus } from "../taskStatus";
26+
import { FinalizeTaskRunService } from "./finalizeTaskRun.server";
2627

2728
type FoundAttempt = Awaited<ReturnType<typeof findAttempt>>;
2829

@@ -50,27 +51,31 @@ export class CompleteAttemptService extends BaseService {
5051
id: execution.attempt.id,
5152
});
5253

53-
/*
54-
"SYSTEM_FAILURE"
55-
56-
Steps:
57-
1. Updates the run to system failure
58-
59-
Inputs:
60-
- taskRun: id
61-
*/
62-
63-
// Update the task run to be failed
64-
await this._prisma.taskRun.update({
54+
const run = await this._prisma.taskRun.findUnique({
6555
where: {
6656
friendlyId: execution.run.id,
6757
},
68-
data: {
69-
status: "SYSTEM_FAILURE",
70-
completedAt: new Date(),
58+
select: {
59+
id: true,
7160
},
7261
});
7362

63+
if (!run) {
64+
logger.error("[CompleteAttemptService] Task run not found", {
65+
friendlyId: execution.run.id,
66+
});
67+
68+
return "COMPLETED";
69+
}
70+
71+
const finalizeService = new FinalizeTaskRunService();
72+
await finalizeService.call({
73+
tx: this._prisma,
74+
id: run.id,
75+
status: "SYSTEM_FAILURE",
76+
completedAt: new Date(),
77+
});
78+
7479
// No attempt, so there's no message to ACK
7580
return "COMPLETED";
7681
}

0 commit comments

Comments
 (0)