@@ -64,9 +64,13 @@ export class FinalizeTaskRunService extends BaseService {
64
64
completedAt,
65
65
} ) ;
66
66
67
+ // I moved the error update here for two reasons:
68
+ // - A single update is more efficient than two
69
+ // - If the status updates to a final status, realtime will receive that status and then shut down the stream
70
+ // before the error is updated, which would cause the error to be lost
67
71
const run = await this . _prisma . taskRun . update ( {
68
72
where : { id } ,
69
- data : { status, expiredAt, completedAt } ,
73
+ data : { status, expiredAt, completedAt, error : error ? sanitizeError ( error ) : undefined } ,
70
74
...( include ? { include } : { } ) ,
71
75
} ) ;
72
76
@@ -78,10 +82,6 @@ export class FinalizeTaskRunService extends BaseService {
78
82
await this . finalizeAttempt ( { attemptStatus, error, run } ) ;
79
83
}
80
84
81
- if ( error ) {
82
- await this . finalizeRunError ( run , error ) ;
83
- }
84
-
85
85
try {
86
86
await this . #finalizeBatch( run ) ;
87
87
} catch ( finalizeBatchError ) {
@@ -211,15 +211,6 @@ export class FinalizeTaskRunService extends BaseService {
211
211
}
212
212
}
213
213
214
- async finalizeRunError ( run : TaskRun , error : TaskRunError ) {
215
- await this . _prisma . taskRun . update ( {
216
- where : { id : run . id } ,
217
- data : {
218
- error : sanitizeError ( error ) ,
219
- } ,
220
- } ) ;
221
- }
222
-
223
214
async finalizeAttempt ( {
224
215
attemptStatus,
225
216
error,
0 commit comments