@@ -23,6 +23,7 @@ import { TaskRun } from "@trigger.dev/database";
23
23
import { PerformTaskAttemptAlertsService } from "./alerts/performTaskAttemptAlerts.server" ;
24
24
import { RetryAttemptService } from "./retryAttempt.server" ;
25
25
import { isFinalAttemptStatus , isFinalRunStatus } from "../taskStatus" ;
26
+ import { FinalizeTaskRunService } from "./finalizeTaskRun.server" ;
26
27
27
28
type FoundAttempt = Awaited < ReturnType < typeof findAttempt > > ;
28
29
@@ -50,27 +51,31 @@ export class CompleteAttemptService extends BaseService {
50
51
id : execution . attempt . id ,
51
52
} ) ;
52
53
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 ( {
65
55
where : {
66
56
friendlyId : execution . run . id ,
67
57
} ,
68
- data : {
69
- status : "SYSTEM_FAILURE" ,
70
- completedAt : new Date ( ) ,
58
+ select : {
59
+ id : true ,
71
60
} ,
72
61
} ) ;
73
62
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
+
74
79
// No attempt, so there's no message to ACK
75
80
return "COMPLETED" ;
76
81
}
0 commit comments