@opentap/runner-client 2.25.2 → 2.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/RunnerClient.js +45 -43
- package/dist/mjs/RunnerClient.js +6 -5
- package/package.json +1 -1
package/dist/cjs/RunnerClient.js
CHANGED
|
@@ -300,88 +300,90 @@ var RunnerClient = /** @class */ (function (_super) {
|
|
|
300
300
|
};
|
|
301
301
|
// Async function here so the loop starts without blocking returning a consumer
|
|
302
302
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
303
|
-
var _loop_1, state_1;
|
|
303
|
+
var consumerInfo, numberPending, _loop_1, state_1;
|
|
304
304
|
var _this = this;
|
|
305
305
|
var e_1, _a;
|
|
306
306
|
return __generator(this, function (_b) {
|
|
307
307
|
switch (_b.label) {
|
|
308
|
-
case 0:
|
|
308
|
+
case 0: return [4 /*yield*/, consumer.info()];
|
|
309
|
+
case 1:
|
|
310
|
+
consumerInfo = _b.sent();
|
|
311
|
+
numberPending = consumerInfo.num_pending;
|
|
309
312
|
_loop_1 = function () {
|
|
310
|
-
var
|
|
313
|
+
var arraySize, metricData_1, messages, index, messages_1, messages_1_1, message, e_1_1, error_1;
|
|
311
314
|
return __generator(this, function (_c) {
|
|
312
315
|
switch (_c.label) {
|
|
313
316
|
case 0:
|
|
314
|
-
_c.trys.push([0,
|
|
315
|
-
|
|
316
|
-
case 1:
|
|
317
|
-
consumerInfo = _c.sent();
|
|
318
|
-
arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
|
|
317
|
+
_c.trys.push([0, 14, , 15]);
|
|
318
|
+
arraySize = Math.max(Math.min(maxBatchSize, numberPending), 1);
|
|
319
319
|
metricData_1 = {
|
|
320
320
|
encodedMetrics: new Array(arraySize),
|
|
321
321
|
timestamps: new Array(arraySize),
|
|
322
322
|
};
|
|
323
323
|
return [4 /*yield*/, consumer.fetch({ max_messages: arraySize })];
|
|
324
|
-
case
|
|
324
|
+
case 1:
|
|
325
325
|
messages = _c.sent();
|
|
326
326
|
index = 0;
|
|
327
|
-
_c.label =
|
|
328
|
-
case
|
|
329
|
-
_c.trys.push([
|
|
327
|
+
_c.label = 2;
|
|
328
|
+
case 2:
|
|
329
|
+
_c.trys.push([2, 7, 8, 13]);
|
|
330
330
|
messages_1 = (e_1 = void 0, __asyncValues(messages));
|
|
331
|
-
_c.label =
|
|
332
|
-
case
|
|
333
|
-
case
|
|
334
|
-
if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/,
|
|
331
|
+
_c.label = 3;
|
|
332
|
+
case 3: return [4 /*yield*/, messages_1.next()];
|
|
333
|
+
case 4:
|
|
334
|
+
if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/, 6];
|
|
335
335
|
message = messages_1_1.value;
|
|
336
336
|
// Store the message data and timestamp
|
|
337
337
|
metricData_1.encodedMetrics[index] = message.data;
|
|
338
338
|
metricData_1.timestamps[index] = message.info.timestampNanos;
|
|
339
|
+
numberPending = message.info.pending;
|
|
339
340
|
// If we are at the last message or there are no more pending messages, call the handler
|
|
340
341
|
if (index === arraySize - 1 || message.info.pending === 0) {
|
|
341
|
-
|
|
342
|
-
return [2 /*return*/, handler(metricData_1)];
|
|
343
|
-
}); }); })();
|
|
344
|
-
return [3 /*break*/, 7];
|
|
342
|
+
return [3 /*break*/, 6];
|
|
345
343
|
}
|
|
346
344
|
// Increment the index
|
|
347
345
|
index++;
|
|
348
|
-
_c.label =
|
|
349
|
-
case
|
|
350
|
-
case
|
|
351
|
-
case
|
|
346
|
+
_c.label = 5;
|
|
347
|
+
case 5: return [3 /*break*/, 3];
|
|
348
|
+
case 6: return [3 /*break*/, 13];
|
|
349
|
+
case 7:
|
|
352
350
|
e_1_1 = _c.sent();
|
|
353
351
|
e_1 = { error: e_1_1 };
|
|
354
|
-
return [3 /*break*/,
|
|
355
|
-
case
|
|
356
|
-
_c.trys.push([
|
|
357
|
-
if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/,
|
|
352
|
+
return [3 /*break*/, 13];
|
|
353
|
+
case 8:
|
|
354
|
+
_c.trys.push([8, , 11, 12]);
|
|
355
|
+
if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/, 10];
|
|
358
356
|
return [4 /*yield*/, _a.call(messages_1)];
|
|
359
|
-
case
|
|
357
|
+
case 9:
|
|
360
358
|
_c.sent();
|
|
361
|
-
_c.label =
|
|
362
|
-
case
|
|
363
|
-
case
|
|
359
|
+
_c.label = 10;
|
|
360
|
+
case 10: return [3 /*break*/, 12];
|
|
361
|
+
case 11:
|
|
364
362
|
if (e_1) throw e_1.error;
|
|
365
363
|
return [7 /*endfinally*/];
|
|
366
|
-
case
|
|
367
|
-
case
|
|
368
|
-
|
|
364
|
+
case 12: return [7 /*endfinally*/];
|
|
365
|
+
case 13:
|
|
366
|
+
(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
367
|
+
return [2 /*return*/, handler(metricData_1)];
|
|
368
|
+
}); }); })();
|
|
369
|
+
return [3 /*break*/, 15];
|
|
370
|
+
case 14:
|
|
369
371
|
error_1 = _c.sent();
|
|
370
372
|
return [2 /*return*/, "break"];
|
|
371
|
-
case
|
|
373
|
+
case 15: return [2 /*return*/];
|
|
372
374
|
}
|
|
373
375
|
});
|
|
374
376
|
};
|
|
375
|
-
_b.label =
|
|
376
|
-
case 1:
|
|
377
|
-
if (!!isCloseInitiated) return [3 /*break*/, 3];
|
|
378
|
-
return [5 /*yield**/, _loop_1()];
|
|
377
|
+
_b.label = 2;
|
|
379
378
|
case 2:
|
|
379
|
+
if (!!isCloseInitiated) return [3 /*break*/, 4];
|
|
380
|
+
return [5 /*yield**/, _loop_1()];
|
|
381
|
+
case 3:
|
|
380
382
|
state_1 = _b.sent();
|
|
381
383
|
if (state_1 === "break")
|
|
382
|
-
return [3 /*break*/,
|
|
383
|
-
return [3 /*break*/,
|
|
384
|
-
case
|
|
384
|
+
return [3 /*break*/, 4];
|
|
385
|
+
return [3 /*break*/, 2];
|
|
386
|
+
case 4: return [2 /*return*/];
|
|
385
387
|
}
|
|
386
388
|
});
|
|
387
389
|
}); })();
|
package/dist/mjs/RunnerClient.js
CHANGED
|
@@ -240,13 +240,13 @@ export class RunnerClient extends BaseClient {
|
|
|
240
240
|
// Async function here so the loop starts without blocking returning a consumer
|
|
241
241
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
242
242
|
var e_1, _a;
|
|
243
|
-
//
|
|
243
|
+
// Get the consumer info to determine the number of pending messages
|
|
244
|
+
const consumerInfo = yield consumer.info();
|
|
245
|
+
let numberPending = consumerInfo.num_pending;
|
|
244
246
|
while (!isCloseInitiated) {
|
|
245
247
|
try {
|
|
246
|
-
// Get the consumer info to determine the number of pending messages
|
|
247
|
-
const consumerInfo = yield consumer.info();
|
|
248
248
|
// We want to define the batch size based on how many message we will consume in the next fetch
|
|
249
|
-
const arraySize = Math.min(maxBatchSize,
|
|
249
|
+
const arraySize = Math.max(Math.min(maxBatchSize, numberPending), 1);
|
|
250
250
|
// Create the object with preallocated arrays for better performance
|
|
251
251
|
const metricData = {
|
|
252
252
|
encodedMetrics: new Array(arraySize),
|
|
@@ -262,9 +262,9 @@ export class RunnerClient extends BaseClient {
|
|
|
262
262
|
// Store the message data and timestamp
|
|
263
263
|
metricData.encodedMetrics[index] = message.data;
|
|
264
264
|
metricData.timestamps[index] = message.info.timestampNanos;
|
|
265
|
+
numberPending = message.info.pending;
|
|
265
266
|
// If we are at the last message or there are no more pending messages, call the handler
|
|
266
267
|
if (index === arraySize - 1 || message.info.pending === 0) {
|
|
267
|
-
(() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
|
|
268
268
|
break;
|
|
269
269
|
}
|
|
270
270
|
// Increment the index
|
|
@@ -278,6 +278,7 @@ export class RunnerClient extends BaseClient {
|
|
|
278
278
|
}
|
|
279
279
|
finally { if (e_1) throw e_1.error; }
|
|
280
280
|
}
|
|
281
|
+
(() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
|
|
281
282
|
}
|
|
282
283
|
catch (error) {
|
|
283
284
|
break;
|