@opentap/runner-client 2.25.0 → 2.25.1

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.
@@ -352,80 +352,100 @@ var SessionClient = /** @class */ (function (_super) {
352
352
  return this.createJetStreamConsumer('Metrics', "M.".concat(metricInfo.subjectPostfix), {
353
353
  domain: this.runnerId,
354
354
  }, { inactive_threshold: (0, nats_ws_1.nanos)(inactiveThresholdMilliseconds) }).then(function (consumer) {
355
+ var isCloseInitiated = false;
356
+ var deleteConsumer = consumer.delete.bind(consumer);
357
+ consumer.delete = function () {
358
+ isCloseInitiated = true;
359
+ return deleteConsumer();
360
+ };
355
361
  // Async function here so the loop starts without blocking returning a consumer
356
362
  (function () { return __awaiter(_this, void 0, void 0, function () {
357
- var _loop_1;
363
+ var _loop_1, state_1;
358
364
  var _this = this;
359
365
  var e_1, _a;
360
366
  return __generator(this, function (_b) {
361
367
  switch (_b.label) {
362
368
  case 0:
363
369
  _loop_1 = function () {
364
- var consumerInfo, arraySize, metricData, messages, index, messages_1, messages_1_1, message, e_1_1;
370
+ var consumerInfo, arraySize, metricData_1, messages, index, messages_1, messages_1_1, message, e_1_1, error_1, error_2;
365
371
  return __generator(this, function (_c) {
366
372
  switch (_c.label) {
367
- case 0: return [4 /*yield*/, consumer.info()];
373
+ case 0:
374
+ _c.trys.push([0, 18, , 19]);
375
+ return [4 /*yield*/, consumer.info()];
368
376
  case 1:
369
377
  consumerInfo = _c.sent();
370
378
  arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
371
- metricData = {
379
+ metricData_1 = {
372
380
  encodedMetrics: new Array(arraySize),
373
381
  timestamps: new Array(arraySize),
374
382
  };
375
- return [4 /*yield*/, consumer.fetch({ max_messages: arraySize })];
383
+ _c.label = 2;
376
384
  case 2:
385
+ _c.trys.push([2, 16, , 17]);
386
+ return [4 /*yield*/, consumer.fetch({ max_messages: arraySize })];
387
+ case 3:
377
388
  messages = _c.sent();
378
389
  index = 0;
379
- _c.label = 3;
380
- case 3:
381
- _c.trys.push([3, 8, 9, 14]);
382
- messages_1 = (e_1 = void 0, __asyncValues(messages));
383
390
  _c.label = 4;
384
- case 4: return [4 /*yield*/, messages_1.next()];
385
- case 5:
386
- if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/, 7];
391
+ case 4:
392
+ _c.trys.push([4, 9, 10, 15]);
393
+ messages_1 = (e_1 = void 0, __asyncValues(messages));
394
+ _c.label = 5;
395
+ case 5: return [4 /*yield*/, messages_1.next()];
396
+ case 6:
397
+ if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/, 8];
387
398
  message = messages_1_1.value;
388
399
  // Store the message data and timestamp
389
- metricData.encodedMetrics[index] = message.data;
390
- metricData.timestamps[index] = message.info.timestampNanos;
400
+ metricData_1.encodedMetrics[index] = message.data;
401
+ metricData_1.timestamps[index] = message.info.timestampNanos;
391
402
  // If we are at the last message or there are no more pending messages, call the handler
392
403
  if (index === arraySize - 1 || message.info.pending === 0) {
393
404
  (function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
394
- return [2 /*return*/, handler(metricData)];
405
+ return [2 /*return*/, handler(metricData_1)];
395
406
  }); }); })();
396
- return [3 /*break*/, 7];
397
407
  }
398
408
  // Increment the index
399
409
  index++;
400
- _c.label = 6;
401
- case 6: return [3 /*break*/, 4];
402
- case 7: return [3 /*break*/, 14];
403
- case 8:
410
+ _c.label = 7;
411
+ case 7: return [3 /*break*/, 5];
412
+ case 8: return [3 /*break*/, 15];
413
+ case 9:
404
414
  e_1_1 = _c.sent();
405
415
  e_1 = { error: e_1_1 };
406
- return [3 /*break*/, 14];
407
- case 9:
408
- _c.trys.push([9, , 12, 13]);
409
- if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/, 11];
410
- return [4 /*yield*/, _a.call(messages_1)];
416
+ return [3 /*break*/, 15];
411
417
  case 10:
418
+ _c.trys.push([10, , 13, 14]);
419
+ if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/, 12];
420
+ return [4 /*yield*/, _a.call(messages_1)];
421
+ case 11:
412
422
  _c.sent();
413
- _c.label = 11;
414
- case 11: return [3 /*break*/, 13];
415
- case 12:
423
+ _c.label = 12;
424
+ case 12: return [3 /*break*/, 14];
425
+ case 13:
416
426
  if (e_1) throw e_1.error;
417
427
  return [7 /*endfinally*/];
418
- case 13: return [7 /*endfinally*/];
419
- case 14: return [2 /*return*/];
428
+ case 14: return [7 /*endfinally*/];
429
+ case 15: return [3 /*break*/, 17];
430
+ case 16:
431
+ error_1 = _c.sent();
432
+ return [2 /*return*/, "break"];
433
+ case 17: return [3 /*break*/, 19];
434
+ case 18:
435
+ error_2 = _c.sent();
436
+ return [2 /*return*/, "break"];
437
+ case 19: return [2 /*return*/];
420
438
  }
421
439
  });
422
440
  };
423
441
  _b.label = 1;
424
442
  case 1:
425
- if (!true) return [3 /*break*/, 3];
443
+ if (!!isCloseInitiated) return [3 /*break*/, 3];
426
444
  return [5 /*yield**/, _loop_1()];
427
445
  case 2:
428
- _b.sent();
446
+ state_1 = _b.sent();
447
+ if (state_1 === "break")
448
+ return [3 /*break*/, 3];
429
449
  return [3 /*break*/, 1];
430
450
  case 3: return [2 /*return*/];
431
451
  }
@@ -293,45 +293,60 @@ export class SessionClient extends BaseClient {
293
293
  return this.createJetStreamConsumer('Metrics', `M.${metricInfo.subjectPostfix}`, {
294
294
  domain: this.runnerId,
295
295
  }, { inactive_threshold: nanos(inactiveThresholdMilliseconds) }).then(consumer => {
296
+ let isCloseInitiated = false;
297
+ const deleteConsumer = consumer.delete.bind(consumer);
298
+ consumer.delete = () => {
299
+ isCloseInitiated = true;
300
+ return deleteConsumer();
301
+ };
296
302
  // Async function here so the loop starts without blocking returning a consumer
297
303
  (() => __awaiter(this, void 0, void 0, function* () {
298
304
  var e_1, _a;
299
305
  // eslint-disable-next-line no-constant-condition
300
- while (true) {
301
- // Get the consumer info to determine the number of pending messages
302
- const consumerInfo = yield consumer.info();
303
- // We want to define the batch size based on how many message we will consume in the next fetch
304
- const arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
305
- // Create the object with preallocated arrays for better performance
306
- const metricData = {
307
- encodedMetrics: new Array(arraySize),
308
- timestamps: new Array(arraySize),
309
- };
310
- // Fetch the messages
311
- const messages = yield consumer.fetch({ max_messages: arraySize });
312
- // for await of doesn't return the index, so we need to keep track of it
313
- let index = 0;
306
+ while (!isCloseInitiated) {
314
307
  try {
315
- for (var messages_1 = (e_1 = void 0, __asyncValues(messages)), messages_1_1; messages_1_1 = yield messages_1.next(), !messages_1_1.done;) {
316
- const message = messages_1_1.value;
317
- // Store the message data and timestamp
318
- metricData.encodedMetrics[index] = message.data;
319
- metricData.timestamps[index] = message.info.timestampNanos;
320
- // If we are at the last message or there are no more pending messages, call the handler
321
- if (index === arraySize - 1 || message.info.pending === 0) {
322
- (() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
323
- break;
308
+ // Get the consumer info to determine the number of pending messages
309
+ const consumerInfo = yield consumer.info();
310
+ // We want to define the batch size based on how many message we will consume in the next fetch
311
+ const arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
312
+ // Create the object with preallocated arrays for better performance
313
+ const metricData = {
314
+ encodedMetrics: new Array(arraySize),
315
+ timestamps: new Array(arraySize),
316
+ };
317
+ try {
318
+ // Fetch the messages
319
+ const messages = yield consumer.fetch({ max_messages: arraySize });
320
+ // for await of doesn't return the index, so we need to keep track of it
321
+ let index = 0;
322
+ try {
323
+ for (var messages_1 = (e_1 = void 0, __asyncValues(messages)), messages_1_1; messages_1_1 = yield messages_1.next(), !messages_1_1.done;) {
324
+ const message = messages_1_1.value;
325
+ // Store the message data and timestamp
326
+ metricData.encodedMetrics[index] = message.data;
327
+ metricData.timestamps[index] = message.info.timestampNanos;
328
+ // If we are at the last message or there are no more pending messages, call the handler
329
+ if (index === arraySize - 1 || message.info.pending === 0) {
330
+ (() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
331
+ }
332
+ // Increment the index
333
+ index++;
334
+ }
335
+ }
336
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
337
+ finally {
338
+ try {
339
+ if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) yield _a.call(messages_1);
340
+ }
341
+ finally { if (e_1) throw e_1.error; }
324
342
  }
325
- // Increment the index
326
- index++;
327
343
  }
328
- }
329
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
330
- finally {
331
- try {
332
- if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) yield _a.call(messages_1);
344
+ catch (error) {
345
+ break;
333
346
  }
334
- finally { if (e_1) throw e_1.error; }
347
+ }
348
+ catch (error) {
349
+ break;
335
350
  }
336
351
  }
337
352
  }))();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.25.0",
3
+ "version": "2.25.1",
4
4
  "description": "This is the web client for the OpenTAP Runner.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/mjs/index.js",