@@ -30,6 +30,11 @@ export class TaskRunHeartbeatFailedService extends BaseService {
3030 supportsLazyAttempts : true ,
3131 } ,
3232 } ,
33+ _count : {
34+ select : {
35+ attempts : true ,
36+ } ,
37+ } ,
3338 } ,
3439 } ) ;
3540
@@ -44,23 +49,32 @@ export class TaskRunHeartbeatFailedService extends BaseService {
4449 switch ( taskRun . status ) {
4550 case "PENDING" : {
4651 if ( taskRun . lockedAt ) {
47- logger . debug (
48- "[RequeueTaskRunService] Failing task run because the heartbeat failed and it's PENDING but locked" ,
49- { taskRun }
50- ) ;
51-
52- const service = new FailedTaskRunService ( ) ;
53-
54- await service . call ( taskRun . friendlyId , {
55- ok : false ,
56- id : taskRun . friendlyId ,
57- retry : undefined ,
58- error : {
59- type : "INTERNAL_ERROR" ,
60- code : TaskRunErrorCodes . TASK_RUN_HEARTBEAT_TIMEOUT ,
61- message : "Did not receive a heartbeat from the worker in time" ,
62- } ,
63- } ) ;
52+ if ( taskRun . _count . attempts === 0 ) {
53+ //no attempts, so we can requeue
54+ logger . debug ( "[RequeueTaskRunService] Requeueing task run, there were no attempts." , {
55+ taskRun,
56+ } ) ;
57+
58+ await marqs ?. nackMessage ( taskRun . id ) ;
59+ } else {
60+ logger . debug (
61+ "[RequeueTaskRunService] Failing task run because the heartbeat failed, it's PENDING, locked, and has attempts" ,
62+ { taskRun }
63+ ) ;
64+
65+ const service = new FailedTaskRunService ( ) ;
66+
67+ await service . call ( taskRun . friendlyId , {
68+ ok : false ,
69+ id : taskRun . friendlyId ,
70+ retry : undefined ,
71+ error : {
72+ type : "INTERNAL_ERROR" ,
73+ code : TaskRunErrorCodes . TASK_RUN_HEARTBEAT_TIMEOUT ,
74+ message : "Did not receive a heartbeat from the worker in time" ,
75+ } ,
76+ } ) ;
77+ }
6478 } else {
6579 logger . debug ( "[RequeueTaskRunService] Nacking task run" , { taskRun } ) ;
6680
0 commit comments