@@ -2,15 +2,11 @@ import { sanitizeError, TaskRunError } from "@trigger.dev/core/v3";
22import { type Prisma , type TaskRun } from "@trigger.dev/database" ;
33import { logger } from "~/services/logger.server" ;
44import { marqs , sanitizeQueueName } from "~/v3/marqs/index.server" ;
5- import {
6- isFailedRunStatus ,
7- type FINAL_ATTEMPT_STATUSES ,
8- type FINAL_RUN_STATUSES ,
9- } from "../taskStatus" ;
5+ import { generateFriendlyId } from "../friendlyIdentifiers" ;
6+ import { FINAL_ATTEMPT_STATUSES , isFailedRunStatus , type FINAL_RUN_STATUSES } from "../taskStatus" ;
107import { PerformTaskRunAlertsService } from "./alerts/performTaskRunAlerts.server" ;
118import { BaseService } from "./baseService.server" ;
129import { ResumeDependentParentsService } from "./resumeDependentParents.server" ;
13- import { generateFriendlyId } from "../friendlyIdentifiers" ;
1410
1511type BaseInput = {
1612 id : string ;
@@ -60,36 +56,20 @@ export class FinalizeTaskRunService extends BaseService {
6056 completedAt,
6157 } ) ;
6258
63- let output : string | undefined = undefined ;
64- let outputType : string | undefined = undefined ;
65-
66- if ( status === "COMPLETED_SUCCESSFULLY" ) {
67- // We need to get the output from the attempt
68- const attempt = await this . _prisma . taskRunAttempt . findFirst ( {
69- where : { taskRunId : id , status : "COMPLETED" , output : { not : null } } ,
70- orderBy : { id : "desc" } ,
71- select : {
72- output : true ,
73- outputType : true ,
74- } ,
75- } ) ;
76-
77- if ( attempt ) {
78- output = attempt . output ?? undefined ;
79- outputType = attempt . outputType ;
80- }
81- }
82-
8359 const run = await this . _prisma . taskRun . update ( {
8460 where : { id } ,
85- data : { status, expiredAt, completedAt, output , outputType } ,
61+ data : { status, expiredAt, completedAt } ,
8662 ...( include ? { include } : { } ) ,
8763 } ) ;
8864
8965 if ( attemptStatus || error ) {
9066 await this . finalizeAttempt ( { attemptStatus, error, run } ) ;
9167 }
9268
69+ if ( isFailedRunStatus ( run . status ) ) {
70+ await this . finalizeRunError ( run , error ) ;
71+ }
72+
9373 //resume any dependencies
9474 const resumeService = new ResumeDependentParentsService ( this . _prisma ) ;
9575 const result = await resumeService . call ( { id : run . id } ) ;
@@ -108,6 +88,19 @@ export class FinalizeTaskRunService extends BaseService {
10888 return run as Output < T > ;
10989 }
11090
91+ async finalizeRunError ( run : TaskRun , error ?: TaskRunError ) {
92+ if ( ! error ) {
93+ return ;
94+ }
95+
96+ await this . _prisma . taskRun . update ( {
97+ where : { id : run . id } ,
98+ data : {
99+ error : sanitizeError ( error ) ,
100+ } ,
101+ } ) ;
102+ }
103+
111104 async finalizeAttempt ( {
112105 attemptStatus,
113106 error,
0 commit comments