@nsshunt/stsrunnerframework 2.0.1 → 2.0.2

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.
@@ -5688,78 +5688,89 @@ ${runnerId}`,
5688
5688
  * If matching runners were found, process them after a short delay.
5689
5689
  * Otherwise just schedule the next scan loop.
5690
5690
  */
5691
- if (removeList.length > 0) setTimeout(async () => {
5692
- this.options.logger.debug(import_source.default.grey(`STSWorkerManager:_processLoopExecutor(): Removing runners from collection: [${JSON.stringify(removeList)}]`));
5693
- /**
5694
- * Process each matched runner from the temporary remove list.
5695
- */
5696
- for (let i = 0; i < removeList.length; i++) {
5697
- const workerEx = this.options.workerRegistry.GetWorkerEx(removeList[i].workerId);
5698
- if (workerEx) {
5699
- const runnerEx = workerEx.GetRunnerEx(removeList[i].runnerId);
5700
- if (runnerEx) {
5701
- /**
5702
- * Stop any active telemetry/instrument publishing for this runner.
5703
- *
5704
- * This is done before archive/delete handling so no further
5705
- * publishing occurs after the runner is considered retired.
5706
- */
5707
- if (runnerEx.publishInstrumentController) {
5708
- this.options.logger.debug(import_source.default.grey(`Ending publish for runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5709
- runnerEx.publishInstrumentController.EndPublish();
5710
- }
5711
- /**
5712
- * Only non-terminated runners are stored in the archive list.
5713
- *
5714
- * Terminated runners are treated as retired/removed but not archived.
5715
- */
5716
- if (runnerEx.state !== IRunnerState.terminated) {
5717
- this.options.logger.debug(import_source.default.grey(`Archive runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5718
- const runner = runnerEx.toRunner();
5719
- this.archiveList.push(runner);
5691
+ if (removeList.length > 0) {
5692
+ const startTimeout = setTimeout(async () => {
5693
+ this.options.logger.debug(import_source.default.grey(`STSWorkerManager:_processLoopExecutor(): Removing runners from collection: [${JSON.stringify(removeList)}]`));
5694
+ /**
5695
+ * Process each matched runner from the temporary remove list.
5696
+ */
5697
+ for (let i = 0; i < removeList.length; i++) {
5698
+ const workerEx = this.options.workerRegistry.GetWorkerEx(removeList[i].workerId);
5699
+ if (workerEx) {
5700
+ const runnerEx = workerEx.GetRunnerEx(removeList[i].runnerId);
5701
+ if (runnerEx) {
5720
5702
  /**
5721
- * Enforce archive list size cap by discarding the oldest item.
5703
+ * Stop any active telemetry/instrument publishing for this runner.
5704
+ *
5705
+ * This is done before archive/delete handling so no further
5706
+ * publishing occurs after the runner is considered retired.
5722
5707
  */
5723
- if (this.archiveList.length > this.options.maxArchiveListLength) this.archiveList.shift();
5724
- } else this.options.logger.debug(import_source.default.grey(`Runner has been terminated and will not be archived, runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5725
- /**
5726
- * Mark as archived regardless of whether it was actually added
5727
- * to the archive list. This prevents the runner from being
5728
- * reprocessed on future scans.
5729
- */
5730
- runnerEx.archived = true;
5731
- /**
5732
- * Schedule deletion of the live runner instance from the worker registry.
5733
- *
5734
- * This removes the runner from the active runtime graph after a delay.
5735
- */
5736
- if (this.archiveDeleteTimeout !== 0) {
5737
- const timeout = setTimeout(() => this.options.workerRegistry.DeleteRunner(workerEx.id, removeList[i].runnerId), this.archiveDeleteTimeout * 1e3);
5708
+ if (runnerEx.publishInstrumentController) {
5709
+ this.options.logger.debug(import_source.default.grey(`Ending publish for runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5710
+ runnerEx.publishInstrumentController.EndPublish();
5711
+ }
5738
5712
  /**
5739
- * In Node.js, unref the timer so it does not keep the process alive.
5713
+ * Only non-terminated runners are stored in the archive list.
5714
+ *
5715
+ * Terminated runners are treated as retired/removed but not archived.
5740
5716
  */
5741
- if (import_browser.default) timeout.unref();
5717
+ if (runnerEx.state !== IRunnerState.terminated) {
5718
+ this.options.logger.debug(import_source.default.grey(`Archive runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5719
+ const runner = runnerEx.toRunner();
5720
+ this.archiveList.push(runner);
5721
+ /**
5722
+ * Enforce archive list size cap by discarding the oldest item.
5723
+ */
5724
+ if (this.archiveList.length > this.options.maxArchiveListLength) this.archiveList.shift();
5725
+ } else this.options.logger.debug(import_source.default.grey(`Runner has been terminated and will not be archived, runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
5726
+ /**
5727
+ * Mark as archived regardless of whether it was actually added
5728
+ * to the archive list. This prevents the runner from being
5729
+ * reprocessed on future scans.
5730
+ */
5731
+ runnerEx.archived = true;
5732
+ /**
5733
+ * Schedule deletion of the live runner instance from the worker registry.
5734
+ *
5735
+ * This removes the runner from the active runtime graph after a delay.
5736
+ */
5737
+ if (this.archiveDeleteTimeout !== 0) {
5738
+ const archiveDelTimeout = setTimeout(() => {
5739
+ try {
5740
+ this.options.workerRegistry.DeleteRunner(workerEx.id, removeList[i].runnerId);
5741
+ } catch (error) {
5742
+ this.options.logger.error(`Error in: this.options.workerRegistry.DeleteRunner(${workerEx.id}, ${removeList[i].runnerId})`);
5743
+ }
5744
+ }, this.archiveDeleteTimeout * 1e3);
5745
+ /**
5746
+ * In Node.js, unref the timer so it does not keep the process alive.
5747
+ */
5748
+ if (import_browser.default) archiveDelTimeout.unref();
5749
+ }
5742
5750
  }
5743
5751
  }
5744
5752
  }
5745
- }
5746
- /**
5747
- * Emit a debug summary showing remaining live runner counts per worker.
5748
- */
5749
- for (const [, workerEx] of Object.entries(this.options.workerRegistry.GetWorkersEx([]))) {
5750
- const message = `STSWorkerManager:_processLoopExecutor(): Remaining runners from worker: [${workerEx.id}]: [${workerEx.GetAllRunnersEx().length}]`;
5751
- this.options.logger.debug(import_source.default.magenta(message));
5752
- }
5753
+ /**
5754
+ * Emit a debug summary showing remaining live runner counts per worker.
5755
+ */
5756
+ for (const [, workerEx] of Object.entries(this.options.workerRegistry.GetWorkersEx([]))) {
5757
+ const message = `STSWorkerManager:_processLoopExecutor(): Remaining runners from worker: [${workerEx.id}]: [${workerEx.GetAllRunnersEx().length}]`;
5758
+ this.options.logger.debug(import_source.default.magenta(message));
5759
+ }
5760
+ /**
5761
+ * Schedule the next archive scan.
5762
+ */
5763
+ this.timeout = setTimeout(() => this.ProcessLoopExecutor(), 1e3);
5764
+ if (import_browser.default) this.timeout.unref();
5765
+ }, 100);
5766
+ if (import_browser.default) startTimeout.unref();
5767
+ } else {
5753
5768
  /**
5754
- * Schedule the next archive scan.
5769
+ * No archive candidates found; just schedule the next scan.
5755
5770
  */
5756
5771
  this.timeout = setTimeout(() => this.ProcessLoopExecutor(), 1e3);
5757
- }, 100);
5758
- else
5759
- /**
5760
- * No archive candidates found; just schedule the next scan.
5761
- */
5762
- this.timeout = setTimeout(() => this.ProcessLoopExecutor(), 1e3);
5772
+ if (import_browser.default) this.timeout.unref();
5773
+ }
5763
5774
  } catch (error) {
5764
5775
  this.options.logger.error(`_processLoopExecutor(): Error: [${error}]`);
5765
5776
  throw error;
@@ -5812,7 +5823,11 @@ ${runnerId}`,
5812
5823
  * - called during overall worker-manager shutdown/termination
5813
5824
  */
5814
5825
  Terminate = () => {
5815
- if (this.timeout) clearTimeout(this.timeout);
5826
+ this.options.logger.debug(`ArchiveManager:Terminate()`);
5827
+ if (this.timeout) {
5828
+ this.options.logger.debug(`ArchiveManager:Terminate() - this.timeout cleared ...`);
5829
+ clearTimeout(this.timeout);
5830
+ }
5816
5831
  };
5817
5832
  };
5818
5833
  //#endregion
@@ -8242,6 +8257,7 @@ ${runnerId}`,
8242
8257
  * - callers should explicitly terminate workers first if desired
8243
8258
  */
8244
8259
  Terminate() {
8260
+ this.options.logger.debug(`STSWorkerManager:Terminate()`);
8245
8261
  this.#archiveManager.Terminate();
8246
8262
  }
8247
8263
  /**