@@ -90,6 +90,8 @@ export class ProdBackgroundWorker {
90
90
) { }
91
91
92
92
async close ( gracefulExitTimeoutElapsed = false ) {
93
+ console . log ( "Closing worker" , { gracefulExitTimeoutElapsed, closed : this . _closed } ) ;
94
+
93
95
if ( this . _closed ) {
94
96
return ;
95
97
}
@@ -104,6 +106,8 @@ export class ProdBackgroundWorker {
104
106
}
105
107
106
108
async #killTaskRunProcess( flush = true , initialSignal : number | NodeJS . Signals = "SIGTERM" ) {
109
+ console . log ( "Killing task run process" , { flush, initialSignal, closed : this . _closed } ) ;
110
+
107
111
if ( this . _closed || ! this . _taskRunProcess ) {
108
112
return ;
109
113
}
@@ -119,6 +123,10 @@ export class ProdBackgroundWorker {
119
123
console . error ( "Error while trying graceful exit" , error ) ;
120
124
} ) ;
121
125
126
+ console . log ( "Killed task run process, setting closed to true" , {
127
+ closed : this . _closed ,
128
+ pid : currentTaskRunProcess . pid ,
129
+ } ) ;
122
130
this . _closed = true ;
123
131
}
124
132
@@ -232,6 +240,9 @@ export class ProdBackgroundWorker {
232
240
payload . execution . worker . version
233
241
) ;
234
242
243
+ console . log ( "Getting fresh task run process, setting closed to false" , {
244
+ closed : this . _closed ,
245
+ } ) ;
235
246
this . _closed = false ;
236
247
237
248
await this . #killCurrentTaskRunProcessBeforeAttempt( ) ;
@@ -250,6 +261,8 @@ export class ProdBackgroundWorker {
250
261
) ;
251
262
252
263
taskRunProcess . onExit . attach ( ( { pid } ) => {
264
+ console . log ( "Task run process exited" , { pid } ) ;
265
+
253
266
// Only delete the task run process if the pid matches
254
267
if ( this . _taskRunProcess ?. pid === pid ) {
255
268
this . _taskRunProcess = undefined ;
@@ -320,12 +333,21 @@ export class ProdBackgroundWorker {
320
333
}
321
334
322
335
async #killCurrentTaskRunProcessBeforeAttempt( ) {
336
+ console . log ( "killCurrentTaskRunProcessBeforeAttempt()" , {
337
+ hasTaskRunProcess : ! ! this . _taskRunProcess ,
338
+ } ) ;
339
+
323
340
if ( ! this . _taskRunProcess ) {
324
341
return ;
325
342
}
326
343
327
344
const currentTaskRunProcess = this . _taskRunProcess ;
328
345
346
+ console . log ( "Killing current task run process" , {
347
+ isBeingKilled : currentTaskRunProcess ?. isBeingKilled ,
348
+ totalBeingKilled : this . _taskRunProcessesBeingKilled . size ,
349
+ } ) ;
350
+
329
351
if ( currentTaskRunProcess . isBeingKilled ) {
330
352
if ( this . _taskRunProcessesBeingKilled . size > 1 ) {
331
353
await this . #tryGracefulExit( currentTaskRunProcess ) ;
@@ -382,6 +404,11 @@ export class ProdBackgroundWorker {
382
404
try {
383
405
const taskRunProcess = await this . #getFreshTaskRunProcess( payload , messageId ) ;
384
406
407
+ console . log ( "executing task run" , {
408
+ attempt : payload . execution . attempt . id ,
409
+ taskRunPid : taskRunProcess . pid ,
410
+ } ) ;
411
+
385
412
const result = await taskRunProcess . executeTaskRun ( payload ) ;
386
413
387
414
if ( result . ok ) {
@@ -477,7 +504,12 @@ export class ProdBackgroundWorker {
477
504
}
478
505
479
506
async cancelAttempt ( attemptId : string ) {
480
- await this . _taskRunProcess ?. cancel ( ) ;
507
+ if ( ! this . _taskRunProcess ) {
508
+ console . error ( "No task run process to cancel attempt" , { attemptId } ) ;
509
+ return ;
510
+ }
511
+
512
+ await this . _taskRunProcess . cancel ( ) ;
481
513
}
482
514
483
515
async executeTaskRunLazyAttempt ( payload : TaskRunExecutionLazyAttemptPayload ) {
@@ -701,6 +733,8 @@ class TaskRunProcess {
701
733
}
702
734
703
735
async cleanup ( kill = false , gracefulExitTimeoutElapsed = false ) {
736
+ console . log ( "cleanup()" , { kill, gracefulExitTimeoutElapsed } ) ;
737
+
704
738
if ( kill && this . _isBeingKilled ) {
705
739
return ;
706
740
}
@@ -715,6 +749,11 @@ class TaskRunProcess {
715
749
// Kill parent unless graceful exit timeout has elapsed and we're in the middle of an execution
716
750
const killParentProcess = kill && ! killChildProcess ;
717
751
752
+ console . log ( "Cleaning up task run process" , {
753
+ killChildProcess,
754
+ killParentProcess,
755
+ } ) ;
756
+
718
757
await this . _ipc ?. sendWithAck ( "CLEANUP" , {
719
758
flush : true ,
720
759
kill : killParentProcess ,
@@ -780,9 +819,13 @@ class TaskRunProcess {
780
819
}
781
820
782
821
async #handleExit( code : number | null , signal : NodeJS . Signals | null ) {
822
+ console . log ( "handling child exit" , { code, signal } ) ;
823
+
783
824
// Go through all the attempts currently pending and reject them
784
825
for ( const [ id , status ] of this . _attemptStatuses . entries ( ) ) {
785
826
if ( status === "PENDING" ) {
827
+ console . log ( "found pending attempt" , { id } ) ;
828
+
786
829
this . _attemptStatuses . set ( id , "REJECTED" ) ;
787
830
788
831
const attemptPromise = this . _attemptPromises . get ( id ) ;
0 commit comments