@@ -30,27 +30,42 @@ export class TaskRunHeartbeatFailedService extends BaseService {
30
30
supportsLazyAttempts : true ,
31
31
} ,
32
32
} ,
33
+ _count : {
34
+ select : {
35
+ attempts : true ,
36
+ } ,
37
+ } ,
33
38
} ,
34
39
} ) ;
35
40
36
41
if ( ! taskRun ) {
37
- logger . error ( "[RequeueTaskRunService ] Task run not found" , {
42
+ logger . error ( "[TaskRunHeartbeatFailedService ] Task run not found" , {
38
43
runId,
39
44
} ) ;
40
45
41
46
return ;
42
47
}
43
48
49
+ const service = new FailedTaskRunService ( ) ;
50
+
44
51
switch ( taskRun . status ) {
45
- case "PENDING" : {
46
- if ( taskRun . lockedAt ) {
52
+ case "PENDING" :
53
+ case "WAITING_TO_RESUME" :
54
+ case "PAUSED" : {
55
+ const backInQueue = await marqs ?. nackMessage ( taskRun . id ) ;
56
+
57
+ if ( backInQueue ) {
47
58
logger . debug (
48
- "[RequeueTaskRunService] Failing task run because the heartbeat failed and it's PENDING but locked" ,
59
+ `[TaskRunHeartbeatFailedService] ${ taskRun . status } run is back in the queue run` ,
60
+ {
61
+ taskRun,
62
+ }
63
+ ) ;
64
+ } else {
65
+ logger . debug (
66
+ `[TaskRunHeartbeatFailedService] ${ taskRun . status } run not back in the queue, failing` ,
49
67
{ taskRun }
50
68
) ;
51
-
52
- const service = new FailedTaskRunService ( ) ;
53
-
54
69
await service . call ( taskRun . friendlyId , {
55
70
ok : false ,
56
71
id : taskRun . friendlyId ,
@@ -61,19 +76,13 @@ export class TaskRunHeartbeatFailedService extends BaseService {
61
76
message : "Did not receive a heartbeat from the worker in time" ,
62
77
} ,
63
78
} ) ;
64
- } else {
65
- logger . debug ( "[RequeueTaskRunService] Nacking task run" , { taskRun } ) ;
66
-
67
- await marqs ?. nackMessage ( taskRun . id ) ;
68
79
}
69
80
70
81
break ;
71
82
}
72
83
case "EXECUTING" :
73
84
case "RETRYING_AFTER_FAILURE" : {
74
- logger . debug ( "[RequeueTaskRunService] Failing task run" , { taskRun } ) ;
75
-
76
- const service = new FailedTaskRunService ( ) ;
85
+ logger . debug ( `[RequeueTaskRunService] ${ taskRun . status } failing task run` , { taskRun } ) ;
77
86
78
87
await service . call ( taskRun . friendlyId , {
79
88
ok : false ,
@@ -90,23 +99,18 @@ export class TaskRunHeartbeatFailedService extends BaseService {
90
99
}
91
100
case "DELAYED" :
92
101
case "WAITING_FOR_DEPLOY" : {
93
- logger . debug ( "[RequeueTaskRunService] Removing task run from queue" , { taskRun } ) ;
102
+ logger . debug (
103
+ `[TaskRunHeartbeatFailedService] ${ taskRun . status } Removing task run from queue` ,
104
+ { taskRun }
105
+ ) ;
94
106
95
107
await marqs ?. acknowledgeMessage (
96
108
taskRun . id ,
97
- "Run is either DELAYED or WAITING_FOR_DEPLOY so we cannot requeue it in RequeueTaskRunService "
109
+ "Run is either DELAYED or WAITING_FOR_DEPLOY so we cannot requeue it in TaskRunHeartbeatFailedService "
98
110
) ;
99
111
100
112
break ;
101
113
}
102
- case "WAITING_TO_RESUME" :
103
- case "PAUSED" : {
104
- logger . debug ( "[RequeueTaskRunService] Requeueing task run" , { taskRun } ) ;
105
-
106
- await marqs ?. nackMessage ( taskRun . id ) ;
107
-
108
- break ;
109
- }
110
114
case "SYSTEM_FAILURE" :
111
115
case "INTERRUPTED" :
112
116
case "CRASHED" :
@@ -115,11 +119,11 @@ export class TaskRunHeartbeatFailedService extends BaseService {
115
119
case "EXPIRED" :
116
120
case "TIMED_OUT" :
117
121
case "CANCELED" : {
118
- logger . debug ( "[RequeueTaskRunService ] Task run is completed" , { taskRun } ) ;
122
+ logger . debug ( "[TaskRunHeartbeatFailedService ] Task run is completed" , { taskRun } ) ;
119
123
120
124
await marqs ?. acknowledgeMessage (
121
125
taskRun . id ,
122
- "Task run is already completed in RequeueTaskRunService "
126
+ "Task run is already completed in TaskRunHeartbeatFailedService "
123
127
) ;
124
128
125
129
try {
@@ -135,7 +139,7 @@ export class TaskRunHeartbeatFailedService extends BaseService {
135
139
delayInMs : taskRun . lockedToVersion ?. supportsLazyAttempts ? 5_000 : undefined ,
136
140
} ) ;
137
141
} catch ( error ) {
138
- logger . error ( "[RequeueTaskRunService ] Error signaling run cancellation" , {
142
+ logger . error ( "[TaskRunHeartbeatFailedService ] Error signaling run cancellation" , {
139
143
runId : taskRun . id ,
140
144
error : error instanceof Error ? error . message : error ,
141
145
} ) ;
0 commit comments