File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
apps/webapp/app/v3/services Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ export class ResumeAttemptService extends BaseService {
2727 take : 1 ,
2828 select : {
2929 id : true ,
30+ number : true ,
31+ status : true ,
3032 } ,
3133 } satisfies Prisma . TaskRunInclude [ "attempts" ] ;
3234
@@ -130,7 +132,20 @@ export class ResumeAttemptService extends BaseService {
130132 return ;
131133 }
132134
133- completedAttemptIds = dependentBatchItems . map ( ( item ) => item . taskRun . attempts [ 0 ] ?. id ) ;
135+ //find the best attempt for each batch item
136+ //it should be the most recent one in a final state
137+ const finalAttempts = dependentBatchItems . map ( ( item ) => {
138+ return item . taskRun . attempts
139+ . filter ( ( a ) => FINAL_ATTEMPT_STATUSES . includes ( a . status ) )
140+ . sort ( ( a , b ) => b . number - a . number ) [ 0 ] ;
141+ } ) ;
142+
143+ completedAttemptIds = finalAttempts . map ( ( a ) => a . id ) ;
144+
145+ if ( completedAttemptIds . length !== dependentBatchItems . length ) {
146+ this . _logger . error ( "[ResumeAttemptService] not all batch items have attempts" ) ;
147+ return ;
148+ }
134149 } else {
135150 this . _logger . error ( "No batch dependency" ) ;
136151 return ;
You can’t perform that action at this time.
0 commit comments