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