@@ -58,7 +58,7 @@ import {
58
58
isFinalAttemptStatus ,
59
59
isFinalRunStatus ,
60
60
} from "../taskStatus" ;
61
- import { SEMINTATTRS_FORCE_RECORDING , tracer } from "../tracer.server" ;
61
+ import { tracer } from "../tracer.server" ;
62
62
import { getMaxDuration } from "../utils/maxDuration" ;
63
63
import { MessagePayload } from "./types" ;
64
64
@@ -120,25 +120,26 @@ export type SharedQueueConsumerOptions = {
120
120
interval ?: number ;
121
121
} ;
122
122
123
+ type HandleMessageAction = "ack_and_do_more_work" | "nack" | "nack_and_do_more_work" | "noop" ;
124
+
123
125
type DoWorkInternalResult =
124
126
| {
125
127
reason : string ;
126
128
attrs ?: Record < string , string | number | boolean | undefined > ;
127
129
error ?: Error | string ;
128
130
interval ?: number ;
131
+ action ?: HandleMessageAction ;
129
132
}
130
133
| undefined ;
131
134
132
- type HandleMessageResult =
133
- | {
134
- action : "ack_and_do_more_work" | "nack" | "nack_and_do_more_work" | "noop" ;
135
- interval ?: number ;
136
- retryInMs ?: number ;
137
- reason ?: string ;
138
- attrs ?: Record < string , string | number | boolean | undefined > ;
139
- error ?: Error | string ;
140
- }
141
- | undefined ;
135
+ type HandleMessageResult = {
136
+ action : HandleMessageAction ;
137
+ interval ?: number ;
138
+ retryInMs ?: number ;
139
+ reason ?: string ;
140
+ attrs ?: Record < string , string | number | boolean | undefined > ;
141
+ error ?: Error | string ;
142
+ } ;
142
143
143
144
export class SharedQueueConsumer {
144
145
private _backgroundWorkers : Map < string , BackgroundWorkerWithTasks > = new Map ( ) ;
@@ -149,6 +150,7 @@ export class SharedQueueConsumer {
149
150
private _traceStartedAt : Date | undefined ;
150
151
private _currentSpanContext : Context | undefined ;
151
152
private _reasonStats : Record < string , number > = { } ;
153
+ private _actionStats : Record < string , number > = { } ;
152
154
private _currentSpan : Span | undefined ;
153
155
private _endSpanInNextIteration = false ;
154
156
private _tasks = sharedQueueTasks ;
@@ -243,14 +245,19 @@ export class SharedQueueConsumer {
243
245
this . _perTraceCountdown = this . _options . maximumItemsPerTrace ;
244
246
this . _traceStartedAt = new Date ( ) ;
245
247
this . _reasonStats = { } ;
248
+ this . _actionStats = { } ;
246
249
247
250
this . #doWork( ) . finally ( ( ) => { } ) ;
248
251
}
249
252
250
253
#endCurrentSpan( ) {
251
254
if ( this . _currentSpan ) {
252
255
for ( const [ reason , count ] of Object . entries ( this . _reasonStats ) ) {
253
- this . _currentSpan . setAttribute ( `reasons.${ reason } ` , count ) ;
256
+ this . _currentSpan . setAttribute ( `reasons_${ reason } ` , count ) ;
257
+ }
258
+
259
+ for ( const [ action , count ] of Object . entries ( this . _actionStats ) ) {
260
+ this . _currentSpan . setAttribute ( `actions_${ action } ` , count ) ;
254
261
}
255
262
256
263
this . _currentSpan . end ( ) ;
@@ -310,6 +317,7 @@ export class SharedQueueConsumer {
310
317
this . _perTraceCountdown = this . _options . maximumItemsPerTrace ;
311
318
this . _traceStartedAt = new Date ( ) ;
312
319
this . _reasonStats = { } ;
320
+ this . _actionStats = { } ;
313
321
this . _iterationsCount = 0 ;
314
322
this . _runningDurationInMs = 0 ;
315
323
this . _endSpanInNextIteration = false ;
@@ -333,6 +341,10 @@ export class SharedQueueConsumer {
333
341
if ( result ) {
334
342
this . _reasonStats [ result . reason ] = ( this . _reasonStats [ result . reason ] ?? 0 ) + 1 ;
335
343
344
+ if ( result . action ) {
345
+ this . _actionStats [ result . action ] = ( this . _actionStats [ result . action ] ?? 0 ) + 1 ;
346
+ }
347
+
336
348
span . setAttribute ( "reason" , result . reason ) ;
337
349
338
350
if ( result . attrs ) {
@@ -357,6 +369,7 @@ export class SharedQueueConsumer {
357
369
span . setAttribute ( "reason" , "no_result" ) ;
358
370
359
371
this . _reasonStats [ "no_result" ] = ( this . _reasonStats [ "no_result" ] ?? 0 ) + 1 ;
372
+ this . _actionStats [ "no_result" ] = ( this . _actionStats [ "no_result" ] ?? 0 ) + 1 ;
360
373
}
361
374
} catch ( error ) {
362
375
if ( error instanceof Error ) {
@@ -436,20 +449,14 @@ export class SharedQueueConsumer {
436
449
437
450
const messageResult = await this . #handleMessage( message , messageBody . data ) ;
438
451
439
- if ( ! messageResult ) {
440
- return {
441
- reason : "no_message_result" ,
442
- attrs : hydrateAttributes ( { } ) ,
443
- } ;
444
- }
445
-
446
452
switch ( messageResult . action ) {
447
453
case "noop" : {
448
454
return {
449
455
reason : messageResult . reason ?? "none_specified" ,
450
456
attrs : hydrateAttributes ( messageResult . attrs ?? { } ) ,
451
457
error : messageResult . error ,
452
458
interval : messageResult . interval ,
459
+ action : "noop" ,
453
460
} ;
454
461
}
455
462
case "ack_and_do_more_work" : {
@@ -460,6 +467,7 @@ export class SharedQueueConsumer {
460
467
attrs : hydrateAttributes ( messageResult . attrs ?? { } ) ,
461
468
error : messageResult . error ,
462
469
interval : messageResult . interval ,
470
+ action : "ack_and_do_more_work" ,
463
471
} ;
464
472
}
465
473
case "nack_and_do_more_work" : {
@@ -470,6 +478,7 @@ export class SharedQueueConsumer {
470
478
attrs : hydrateAttributes ( messageResult . attrs ?? { } ) ,
471
479
error : messageResult . error ,
472
480
interval : messageResult . interval ,
481
+ action : "nack_and_do_more_work" ,
473
482
} ;
474
483
}
475
484
case "nack" : {
@@ -479,6 +488,7 @@ export class SharedQueueConsumer {
479
488
reason : messageResult . reason ?? "none_specified" ,
480
489
attrs : hydrateAttributes ( messageResult . attrs ?? { } ) ,
481
490
error : messageResult . error ,
491
+ action : "nack" ,
482
492
} ;
483
493
}
484
494
}
@@ -609,7 +619,6 @@ export class SharedQueueConsumer {
609
619
action : "ack_and_do_more_work" ,
610
620
reason : "missing_image_reference" ,
611
621
attrs : {
612
- run_id : existingTaskRun . id ,
613
622
deployment_id : deployment . id ,
614
623
} ,
615
624
} ;
@@ -710,7 +719,7 @@ export class SharedQueueConsumer {
710
719
} ) ;
711
720
712
721
return {
713
- action : "nack_and_do_more_work " ,
722
+ action : "ack_and_do_more_work " ,
714
723
reason : "failed_to_lock_task_run" ,
715
724
attrs : {
716
725
run_id : existingTaskRun . id ,
@@ -791,11 +800,18 @@ export class SharedQueueConsumer {
791
800
attrs : {
792
801
run_status : lockedTaskRun . status ,
793
802
is_retry : isRetry ,
803
+ checkpoint_event_id : data . checkpointEventId ,
794
804
} ,
795
805
} ;
796
806
}
797
807
798
- return ;
808
+ return {
809
+ action : "noop" ,
810
+ reason : "restored_checkpoint" ,
811
+ attrs : {
812
+ checkpoint_event_id : data . checkpointEventId ,
813
+ } ,
814
+ } ;
799
815
}
800
816
801
817
if ( ! worker . supportsLazyAttempts ) {
@@ -806,7 +822,7 @@ export class SharedQueueConsumer {
806
822
setToExecuting : false ,
807
823
} ) ;
808
824
} catch ( error ) {
809
- logger . error ( "Failed to create task run attempt for outdate worker" , {
825
+ logger . error ( "Failed to create task run attempt for outdated worker" , {
810
826
error,
811
827
taskRun : lockedTaskRun . id ,
812
828
} ) ;
@@ -818,7 +834,7 @@ export class SharedQueueConsumer {
818
834
819
835
return {
820
836
action : "ack_and_do_more_work" ,
821
- reason : "failed_to_create_attempt " ,
837
+ reason : "failed_to_create_attempt_for_outdated_worker " ,
822
838
attrs : {
823
839
message_id : message . messageId ,
824
840
run_id : lockedTaskRun . id ,
@@ -931,6 +947,9 @@ export class SharedQueueConsumer {
931
947
return {
932
948
action : "noop" ,
933
949
reason : "restored_checkpoint" ,
950
+ attrs : {
951
+ checkpoint_event_id : data . checkpointEventId ,
952
+ } ,
934
953
} ;
935
954
} catch ( e ) {
936
955
return {
@@ -992,7 +1011,7 @@ export class SharedQueueConsumer {
992
1011
993
1012
return {
994
1013
action : "ack_and_do_more_work" ,
995
- reason : "attempt_not_found " ,
1014
+ reason : "resumable_attempt_not_found " ,
996
1015
attrs : {
997
1016
attempt_id : data . resumableAttemptId ,
998
1017
} ,
@@ -1215,6 +1234,9 @@ export class SharedQueueConsumer {
1215
1234
return {
1216
1235
action : "noop" ,
1217
1236
reason : "restored_checkpoint" ,
1237
+ attrs : {
1238
+ checkpoint_event_id : data . checkpointEventId ,
1239
+ } ,
1218
1240
} ;
1219
1241
} else {
1220
1242
logger . debug (
0 commit comments