@@ -19,30 +19,42 @@ export class DynamicFlushScheduler<T> {
19
19
private readonly concurrencyLimiter : ReturnType < typeof pLimit > ;
20
20
private flushTimer : NodeJS . Timeout | null ;
21
21
private readonly callback : ( flushId : string , batch : T [ ] ) => Promise < void > ;
22
- private isShuttingDown = false ;
22
+ private isShuttingDown ;
23
+ private failedBatchCount ;
23
24
24
25
constructor ( config : DynamicFlushSchedulerConfig < T > ) {
25
26
this . currentBatch = [ ] ;
26
27
this . BATCH_SIZE = config . batchSize ;
27
28
this . FLUSH_INTERVAL = config . flushInterval ;
28
29
this . MAX_CONCURRENCY = config . maxConcurrency || 1 ;
29
30
this . concurrencyLimiter = pLimit ( this . MAX_CONCURRENCY ) ;
30
- this . callback = config . callback ;
31
31
this . flushTimer = null ;
32
+ this . callback = config . callback ;
33
+ this . isShuttingDown = false ;
34
+ this . failedBatchCount = 0 ;
32
35
this . startFlushTimer ( ) ;
33
36
this . setupShutdownHandlers ( ) ;
34
37
35
- // if (process.env.NODE_ENV !== "test") {
36
- // const scheduler = this;
37
- // new Gauge({
38
- // name: "dynamic_flush_scheduler_batch_size",
39
- // help: "Number of items in the current dynamic flush scheduler batch",
40
- // collect() {
41
- // this.set(scheduler.currentBatch.length);
42
- // },
43
- // registers: [metricsRegister],
44
- // });
45
- // }
38
+ if ( process . env . NODE_ENV !== "test" ) {
39
+ const scheduler = this ;
40
+ new Gauge ( {
41
+ name : "dynamic_flush_scheduler_batch_size" ,
42
+ help : "Number of items in the current dynamic flush scheduler batch" ,
43
+ collect ( ) {
44
+ this . set ( scheduler . currentBatch . length ) ;
45
+ } ,
46
+ registers : [ metricsRegister ] ,
47
+ } ) ;
48
+
49
+ new Gauge ( {
50
+ name : "dynamic_flush_scheduler_failed_batches" ,
51
+ help : "Number of failed batches" ,
52
+ collect ( ) {
53
+ this . set ( scheduler . failedBatchCount ) ;
54
+ } ,
55
+ registers : [ metricsRegister ] ,
56
+ } ) ;
57
+ }
46
58
}
47
59
48
60
async addToBatch ( items : T [ ] ) : Promise < void > {
@@ -113,10 +125,14 @@ export class DynamicFlushScheduler<T> {
113
125
batchId,
114
126
error,
115
127
} ) ;
128
+ throw error ;
116
129
}
117
130
} )
118
131
) ;
119
132
120
- await Promise . all ( promises ) ;
133
+ const results = await Promise . allSettled ( promises ) ;
134
+
135
+ const failedBatches = results . filter ( ( result ) => result . status === "rejected" ) . length ;
136
+ this . failedBatchCount += failedBatches ;
121
137
}
122
138
}
0 commit comments