@nsshunt/stsrunnerframework 1.0.174 → 1.0.176

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.
@@ -1,19 +1,7 @@
1
1
  (function(global2, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nsshunt/stsutils"), require("@nsshunt/stsobservability")) : typeof define === "function" && define.amd ? define(["exports", "@nsshunt/stsutils", "@nsshunt/stsobservability"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2["@nsshunt/stsrunnerframework"] = {}, global2.stsutils, global2.stsobservability));
3
- })(this, function(exports2, stsutils, stsobservability) {
4
- "use strict";var __defProp = Object.defineProperty;
5
- var __typeError = (msg) => {
6
- throw TypeError(msg);
7
- };
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
11
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
12
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
14
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
15
-
16
- var _collectorCollectorPort, _runners, _options, _workerId, _archiveDeleteTimeout, _logMessage, _silly, _debug, _info, _warn, _error, _processLoopExecutor, _SetMessagePort, _CreateRunnerEx2RunState, _UpdateRunnerStateById, _CanExecuteNextIterationById, _IsCompletedById, _GetRunnerIterationById, _ResetRunnerIterationById, _IncRunnerIterationById, _GetRunnerInstanceById, _GetRunnerExecutionProfileById, _GetRunnerOptionsById, _SetRunnerOptionsById, _AddRunner, _WorkerInstance_instances, SleepImmediate_fn, _PostMessageToWorkerManagerById, _PostRunnersToWorkerManager, _StartRunner, _StopRunnerByRunnerId, _StopRunner, _TerminateRunner, _SendRunnerCommandResponse, _PauseRunner, _ResumeRunner, _ResetRunner, _ExecuteRunner, _UpdateRunner, _workersEx, _options2, _STSInstrumentController, _telemetryProcessor, _archiveList, _id, _messages, _archiveDeleteTimeout2, _logMessage2, _silly2, _debug2, _info2, _warn2, _error2, _processLoopExecutor2, _SetRunnerIntoWorker, _ProcessTelemetry, _EmitWorkerEvent, _EmitRunnerEvent, _RunnerStateChange, _CreateAsyncRunner, _PostMessageToWorkerUsingDefaultChannel, _StartRunner2, _StopRunner2, _ResetRunner2, _ExecuteRunner2, _TerminateRunner2, _PauseRunner2, _ResumeRunner2, _UpdateRunner2, _StartWorker, _StopWorker, _PauseWorker, _ResumeWorker, _ResetWorker, _ExecuteWorker, _UpdateOptionsWorker, _TerminateWorker, _ProcessWorkerCommands, _ExecuteVariableCommandOnRunners, _STSWorkerManager_instances, GetRunnersResponse_fn, ProcessRunnerResponse_fn, _SyncRunnerData, _SyncWorkerDataFromPayload, _SyncWorkerDataFromWorker, _SyncWorkerDataFromWorkers, _SetupCallbackMessage, _PostMessageToWorkerGetRunners;
3
+ })(this, (function(exports2, stsutils, stsobservability) {
4
+ "use strict";
17
5
  var eIWMessageCommands = /* @__PURE__ */ ((eIWMessageCommands2) => {
18
6
  eIWMessageCommands2["InstrumentTelemetry"] = "__STS__InstrumentTelemetry";
19
7
  eIWMessageCommands2["MessagePort"] = "__STS__MessagePort";
@@ -1533,785 +1521,735 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1533
1521
  const chalk = /* @__PURE__ */ getDefaultExportFromCjs(sourceExports);
1534
1522
  chalk.level = 3;
1535
1523
  class WorkerInstance {
1536
- constructor() {
1537
- __privateAdd(this, _WorkerInstance_instances);
1538
- __privateAdd(this, _collectorCollectorPort, null);
1539
- __privateAdd(this, _runners, {});
1540
- __privateAdd(this, _options, null);
1541
- __privateAdd(this, _workerId, null);
1542
- __privateAdd(this, _archiveDeleteTimeout, 30);
1543
- __privateAdd(this, _logMessage, (fn, message) => {
1544
- if (__privateGet(this, _options)) {
1545
- fn(`pid: [${process.pid}] WorkerInstance: Worker ID: [${__privateGet(this, _workerId)}] Log: [${message}]`);
1546
- } else {
1547
- fn(`pid: [${process.pid}] WorkerInstance: Log: [${message}]`);
1548
- }
1549
- });
1550
- __privateAdd(this, _silly, (message) => {
1551
- if (__privateGet(this, _options) && __privateGet(this, _options).logLevel >= 5) {
1552
- __privateGet(this, _logMessage).call(this, this.logger.silly, message);
1553
- }
1554
- });
1555
- __privateAdd(this, _debug, (message) => {
1556
- if (__privateGet(this, _options) && __privateGet(this, _options).logLevel >= 4) {
1557
- __privateGet(this, _logMessage).call(this, this.logger.debug, message);
1558
- }
1559
- });
1560
- __privateAdd(this, _info, (message) => {
1561
- if (__privateGet(this, _options) && __privateGet(this, _options).logLevel >= 3) {
1562
- __privateGet(this, _logMessage).call(this, this.logger.info, message);
1563
- }
1564
- });
1565
- __privateAdd(this, _warn, (message) => {
1566
- if (__privateGet(this, _options) && __privateGet(this, _options).logLevel >= 2) {
1567
- __privateGet(this, _logMessage).call(this, this.logger.warn, message);
1568
- }
1569
- });
1570
- __privateAdd(this, _error, (error) => {
1571
- if (__privateGet(this, _options) && __privateGet(this, _options).logLevel >= 1) {
1572
- __privateGet(this, _logMessage).call(this, this.logger.error, error);
1573
- }
1574
- });
1575
- __privateAdd(this, _processLoopExecutor, async () => {
1576
- try {
1577
- const removeList = [];
1578
- for (const [, runner] of Object.entries(__privateGet(this, _runners))) {
1579
- if (runner.archived === false && (runner.runner.state === IRunnerState.completed || runner.runner.state === IRunnerState.error || runner.runner.state === IRunnerState.stopped || runner.runner.state === IRunnerState.terminated)) {
1580
- removeList.push(runner.runner.id);
1581
- }
1524
+ #collectorCollectorPort = null;
1525
+ #runners = {};
1526
+ #options = null;
1527
+ #workerId = null;
1528
+ #archiveDeleteTimeout = 30;
1529
+ get logger() {
1530
+ return stsutils.defaultLogger;
1531
+ }
1532
+ #logMessage = (fn, message) => {
1533
+ if (this.#options) {
1534
+ fn(`pid: [${process.pid}] WorkerInstance: Worker ID: [${this.#workerId}] Log: [${message}]`);
1535
+ } else {
1536
+ fn(`pid: [${process.pid}] WorkerInstance: Log: [${message}]`);
1537
+ }
1538
+ };
1539
+ #silly = (message) => {
1540
+ if (this.#options && this.#options.logLevel >= 5) {
1541
+ this.#logMessage(this.logger.silly, message);
1542
+ }
1543
+ };
1544
+ #debug = (message) => {
1545
+ if (this.#options && this.#options.logLevel >= 4) {
1546
+ this.#logMessage(this.logger.debug, message);
1547
+ }
1548
+ };
1549
+ #info = (message) => {
1550
+ if (this.#options && this.#options.logLevel >= 3) {
1551
+ this.#logMessage(this.logger.info, message);
1552
+ }
1553
+ };
1554
+ #warn = (message) => {
1555
+ if (this.#options && this.#options.logLevel >= 2) {
1556
+ this.#logMessage(this.logger.warn, message);
1557
+ }
1558
+ };
1559
+ #error = (error) => {
1560
+ if (this.#options && this.#options.logLevel >= 1) {
1561
+ this.#logMessage(this.logger.error, error);
1562
+ }
1563
+ };
1564
+ #processLoopExecutor = async () => {
1565
+ try {
1566
+ const removeList = [];
1567
+ for (const [, runner] of Object.entries(this.#runners)) {
1568
+ if (runner.archived === false && (runner.runner.state === IRunnerState.completed || runner.runner.state === IRunnerState.error || runner.runner.state === IRunnerState.stopped || runner.runner.state === IRunnerState.terminated)) {
1569
+ removeList.push(runner.runner.id);
1582
1570
  }
1583
- if (removeList.length > 0) {
1584
- setTimeout(() => {
1585
- __privateGet(this, _debug).call(this, chalk.grey(`WorkerInstance:#processLoopExecutor(): Removing runners from collection: [${removeList}]`));
1586
- for (let i = 0; i < removeList.length; i++) {
1587
- __privateGet(this, _runners)[removeList[i]].archived = true;
1588
- if (__privateGet(this, _archiveDeleteTimeout) !== 0) {
1589
- if (isNode) {
1590
- setTimeout(() => delete __privateGet(this, _runners)[removeList[i]], __privateGet(this, _archiveDeleteTimeout) * 1e3).unref();
1591
- } else {
1592
- setTimeout(() => delete __privateGet(this, _runners)[removeList[i]], __privateGet(this, _archiveDeleteTimeout) * 1e3);
1593
- }
1571
+ }
1572
+ if (removeList.length > 0) {
1573
+ setTimeout(() => {
1574
+ this.#debug(chalk.grey(`WorkerInstance:#processLoopExecutor(): Removing runners from collection: [${removeList}]`));
1575
+ for (let i = 0; i < removeList.length; i++) {
1576
+ this.#runners[removeList[i]].archived = true;
1577
+ if (this.#archiveDeleteTimeout !== 0) {
1578
+ if (isNode) {
1579
+ setTimeout(() => delete this.#runners[removeList[i]], this.#archiveDeleteTimeout * 1e3).unref();
1580
+ } else {
1581
+ setTimeout(() => delete this.#runners[removeList[i]], this.#archiveDeleteTimeout * 1e3);
1594
1582
  }
1595
1583
  }
1596
- __privateGet(this, _debug).call(this, chalk.grey(`WorkerInstance:#processLoopExecutor(): Remaining Runner Count: [${Object.keys(__privateGet(this, _runners)).length}]`));
1597
- setTimeout(__privateGet(this, _processLoopExecutor), 1e3);
1598
- }, 100);
1599
- } else {
1600
- setTimeout(__privateGet(this, _processLoopExecutor), 1e3);
1601
- }
1602
- } catch (error) {
1603
- __privateGet(this, _error).call(this, `#processLoopExecutor(): [${error}]`);
1604
- setTimeout(__privateGet(this, _processLoopExecutor), 1e3);
1605
- }
1606
- });
1607
- __publicField(this, "GetRandomInt", (max) => {
1608
- return Math.floor(Math.random() * Math.floor(max));
1609
- });
1610
- __publicField(this, "PostTelemetryById", (id) => {
1611
- __privateGet(this, _PostMessageToWorkerManagerById).call(this, eIWMessageCommands.InstrumentTelemetry, id, false);
1612
- });
1613
- __privateAdd(this, _SetMessagePort, (workerMessagePort) => {
1614
- try {
1615
- __privateSet(this, _collectorCollectorPort, workerMessagePort.port);
1616
- if (isNode) {
1617
- __privateGet(this, _collectorCollectorPort).on("message", (data) => {
1618
- __privateGet(this, _silly).call(this, `collectorCollectorPort on('message'): ${JSON.stringify(data)}`);
1619
- });
1620
- } else {
1621
- __privateGet(this, _collectorCollectorPort).addEventListener("message", (data) => {
1622
- __privateGet(this, _silly).call(this, `collectorCollectorPort addEventListener('message'): ${JSON.stringify(data.data)}`);
1623
- });
1624
- }
1625
- const response = {
1626
- command: eIWMessageCommands.MessagePortResponse,
1627
- payload: {}
1628
- };
1629
- __privateGet(this, _collectorCollectorPort).postMessage(response);
1630
- } catch (error) {
1631
- __privateGet(this, _error).call(this, `#SetMessagePort(): [${error}]`);
1584
+ }
1585
+ this.#debug(chalk.grey(`WorkerInstance:#processLoopExecutor(): Remaining Runner Count: [${Object.keys(this.#runners).length}]`));
1586
+ setTimeout(this.#processLoopExecutor, 1e3);
1587
+ }, 100);
1588
+ } else {
1589
+ setTimeout(this.#processLoopExecutor, 1e3);
1632
1590
  }
1633
- });
1634
- __publicField(this, "CreateAsyncRunner", async (testRunnerTelemetryPayload) => {
1635
- return null;
1636
- });
1637
- __privateAdd(this, _CreateRunnerEx2RunState, async (runner, runnerInstance) => {
1638
- try {
1639
- __privateGet(this, _runners)[runner.id] = {
1640
- runner,
1641
- runnerInstance,
1642
- archived: false
1643
- };
1644
- __privateGet(this, _runners)[runner.id].runner.iteration = 0;
1645
- __privateGet(this, _UpdateRunnerStateById).call(this, "#CreateRunnerEx2RunState", runner.id, IRunnerState.created);
1646
- } catch (error) {
1647
- __privateGet(this, _error).call(this, `#CreateRunnerEx2RunState(): [${error}]`);
1591
+ } catch (error) {
1592
+ this.#error(`#processLoopExecutor(): [${error}]`);
1593
+ setTimeout(this.#processLoopExecutor, 1e3);
1594
+ }
1595
+ };
1596
+ constructor() {
1597
+ this.#processLoopExecutor();
1598
+ }
1599
+ GetRandomInt = (max) => {
1600
+ return Math.floor(Math.random() * Math.floor(max));
1601
+ };
1602
+ PostTelemetryById = (id) => {
1603
+ this.#PostMessageToWorkerManagerById(eIWMessageCommands.InstrumentTelemetry, id, false);
1604
+ };
1605
+ get CollectorCollectorPort() {
1606
+ return this.#collectorCollectorPort;
1607
+ }
1608
+ get Options() {
1609
+ return this.#options;
1610
+ }
1611
+ #SetMessagePort = (workerMessagePort) => {
1612
+ try {
1613
+ this.#collectorCollectorPort = workerMessagePort.port;
1614
+ if (isNode) {
1615
+ this.#collectorCollectorPort.on("message", (data) => {
1616
+ this.#silly(`collectorCollectorPort on('message'): ${JSON.stringify(data)}`);
1617
+ });
1618
+ } else {
1619
+ this.#collectorCollectorPort.addEventListener("message", (data) => {
1620
+ this.#silly(`collectorCollectorPort addEventListener('message'): ${JSON.stringify(data.data)}`);
1621
+ });
1648
1622
  }
1649
- });
1650
- __privateAdd(this, _UpdateRunnerStateById, (fromContext, id, state) => {
1651
- try {
1652
- if (__privateGet(this, _runners)[id]) {
1653
- const previousState = __privateGet(this, _runners)[id].runner.state;
1654
- __privateGet(this, _runners)[id].runner.state = state;
1655
- __privateGet(this, _debug).call(this, `#UpdateRunnerStateById(): Context: [${fromContext}] Previous State: [${previousState}] New State: [${state}]`);
1656
- __privateGet(this, _PostMessageToWorkerManagerById).call(this, eIWMessageCommands.RunnerStateChange, id, false);
1657
- } else {
1658
- __privateGet(this, _warn).call(this, `#UpdateRunnerStateById(): Runner ID: [${id}] not found`);
1659
- }
1660
- } catch (error) {
1661
- __privateGet(this, _error).call(this, `#UpdateRunnerStateById(): [${error}]`);
1623
+ const response = {
1624
+ command: eIWMessageCommands.MessagePortResponse,
1625
+ payload: {}
1626
+ };
1627
+ this.#collectorCollectorPort.postMessage(response);
1628
+ } catch (error) {
1629
+ this.#error(`#SetMessagePort(): [${error}]`);
1630
+ }
1631
+ };
1632
+ CreateAsyncRunner = async (testRunnerTelemetryPayload) => {
1633
+ return null;
1634
+ };
1635
+ #CreateRunnerEx2RunState = async (runner, runnerInstance) => {
1636
+ try {
1637
+ this.#runners[runner.id] = {
1638
+ runner,
1639
+ runnerInstance,
1640
+ archived: false
1641
+ };
1642
+ this.#runners[runner.id].runner.iteration = 0;
1643
+ this.#UpdateRunnerStateById("#CreateRunnerEx2RunState", runner.id, IRunnerState.created);
1644
+ } catch (error) {
1645
+ this.#error(`#CreateRunnerEx2RunState(): [${error}]`);
1646
+ }
1647
+ };
1648
+ #UpdateRunnerStateById = (fromContext, id, state) => {
1649
+ try {
1650
+ if (this.#runners[id]) {
1651
+ const previousState = this.#runners[id].runner.state;
1652
+ this.#runners[id].runner.state = state;
1653
+ this.#debug(`#UpdateRunnerStateById(): Context: [${fromContext}] Previous State: [${previousState}] New State: [${state}]`);
1654
+ this.#PostMessageToWorkerManagerById(eIWMessageCommands.RunnerStateChange, id, false);
1655
+ } else {
1656
+ this.#warn(`#UpdateRunnerStateById(): Runner ID: [${id}] not found`);
1662
1657
  }
1663
- });
1664
- // If an error occurs or the runner does not exist, treat as cannot execute next iteration
1665
- __privateAdd(this, _CanExecuteNextIterationById, (id) => {
1666
- try {
1667
- if (__privateGet(this, _runners)[id]) {
1668
- const state = __privateGet(this, _runners)[id].runner.state;
1669
- if (state === IRunnerState.running) {
1670
- return true;
1671
- }
1672
- return false;
1673
- } else {
1674
- __privateGet(this, _warn).call(this, `#CanExecuteNextIterationById(): Runner ID: [${id}] not found`);
1675
- return false;
1658
+ } catch (error) {
1659
+ this.#error(`#UpdateRunnerStateById(): [${error}]`);
1660
+ }
1661
+ };
1662
+ // If an error occurs or the runner does not exist, treat as cannot execute next iteration
1663
+ #CanExecuteNextIterationById = (id) => {
1664
+ try {
1665
+ if (this.#runners[id]) {
1666
+ const state = this.#runners[id].runner.state;
1667
+ if (state === IRunnerState.running) {
1668
+ return true;
1676
1669
  }
1677
- } catch (error) {
1678
- __privateGet(this, _error).call(this, `#CanExecuteNextIterationById(): [${error}]`);
1670
+ return false;
1671
+ } else {
1672
+ this.#warn(`#CanExecuteNextIterationById(): Runner ID: [${id}] not found`);
1679
1673
  return false;
1680
1674
  }
1681
- });
1682
- // If an error occurs or the runner does not exist, treat as completed.
1683
- __privateAdd(this, _IsCompletedById, (id) => {
1684
- try {
1685
- if (__privateGet(this, _runners)[id]) {
1686
- const state = __privateGet(this, _runners)[id].runner.state;
1687
- if (state === IRunnerState.error || state === IRunnerState.completed || state === IRunnerState.stopped || state === IRunnerState.terminated) {
1688
- return true;
1689
- }
1690
- return false;
1691
- } else {
1692
- __privateGet(this, _warn).call(this, `#IsCompletedById(): Runner ID: [${id}] not found`);
1675
+ } catch (error) {
1676
+ this.#error(`#CanExecuteNextIterationById(): [${error}]`);
1677
+ return false;
1678
+ }
1679
+ };
1680
+ // If an error occurs or the runner does not exist, treat as completed.
1681
+ #IsCompletedById = (id) => {
1682
+ try {
1683
+ if (this.#runners[id]) {
1684
+ const state = this.#runners[id].runner.state;
1685
+ if (state === IRunnerState.error || state === IRunnerState.completed || state === IRunnerState.stopped || state === IRunnerState.terminated) {
1693
1686
  return true;
1694
1687
  }
1695
- } catch (error) {
1696
- __privateGet(this, _error).call(this, `#IsCompletedById(): [${error}]`);
1688
+ return false;
1689
+ } else {
1690
+ this.#warn(`#IsCompletedById(): Runner ID: [${id}] not found`);
1697
1691
  return true;
1698
1692
  }
1699
- });
1700
- __privateAdd(this, _GetRunnerIterationById, (id) => {
1701
- try {
1702
- if (__privateGet(this, _runners)[id]) {
1703
- return __privateGet(this, _runners)[id].runner.iteration;
1704
- } else {
1705
- __privateGet(this, _warn).call(this, `#GetRunnerIterationById(): Runner ID: [${id}] not found`);
1706
- return 0;
1707
- }
1708
- } catch (error) {
1709
- __privateGet(this, _error).call(this, `#GetRunnerIterationById(): [${error}]`);
1693
+ } catch (error) {
1694
+ this.#error(`#IsCompletedById(): [${error}]`);
1695
+ return true;
1696
+ }
1697
+ };
1698
+ #GetRunnerIterationById = (id) => {
1699
+ try {
1700
+ if (this.#runners[id]) {
1701
+ return this.#runners[id].runner.iteration;
1702
+ } else {
1703
+ this.#warn(`#GetRunnerIterationById(): Runner ID: [${id}] not found`);
1710
1704
  return 0;
1711
1705
  }
1712
- });
1713
- __privateAdd(this, _ResetRunnerIterationById, (id) => {
1714
- try {
1715
- if (__privateGet(this, _runners)[id]) {
1716
- __privateGet(this, _runners)[id].runner.iteration = 0;
1717
- return 0;
1718
- } else {
1719
- __privateGet(this, _warn).call(this, `#ResetRunnerIterationById(): Runner ID: [${id}] not found`);
1720
- return 0;
1721
- }
1722
- } catch (error) {
1723
- __privateGet(this, _error).call(this, `#ResetRunnerIterationById(): [${error}]`);
1706
+ } catch (error) {
1707
+ this.#error(`#GetRunnerIterationById(): [${error}]`);
1708
+ return 0;
1709
+ }
1710
+ };
1711
+ #ResetRunnerIterationById = (id) => {
1712
+ try {
1713
+ if (this.#runners[id]) {
1714
+ this.#runners[id].runner.iteration = 0;
1724
1715
  return 0;
1725
- }
1726
- });
1727
- __privateAdd(this, _IncRunnerIterationById, (id) => {
1728
- try {
1729
- if (__privateGet(this, _runners)[id]) {
1730
- __privateGet(this, _runners)[id].runner.iteration++;
1731
- return __privateGet(this, _runners)[id].runner.iteration;
1732
- } else {
1733
- __privateGet(this, _warn).call(this, `#IncRunnerIterationById(): Runner ID: [${id}] not found`);
1734
- return 0;
1735
- }
1736
- } catch (error) {
1737
- __privateGet(this, _error).call(this, `#IncRunnerIterationById(): [${error}]`);
1716
+ } else {
1717
+ this.#warn(`#ResetRunnerIterationById(): Runner ID: [${id}] not found`);
1738
1718
  return 0;
1739
1719
  }
1740
- });
1741
- __privateAdd(this, _GetRunnerInstanceById, (id) => {
1742
- try {
1743
- if (__privateGet(this, _runners)[id]) {
1744
- return __privateGet(this, _runners)[id].runnerInstance;
1745
- } else {
1746
- __privateGet(this, _warn).call(this, `#GetRunnerInstanceById(): Runner ID: [${id}] not found`);
1747
- }
1748
- } catch (error) {
1749
- __privateGet(this, _error).call(this, `#GetRunnerInstanceById(): [${error}]`);
1720
+ } catch (error) {
1721
+ this.#error(`#ResetRunnerIterationById(): [${error}]`);
1722
+ return 0;
1723
+ }
1724
+ };
1725
+ #IncRunnerIterationById = (id) => {
1726
+ try {
1727
+ if (this.#runners[id]) {
1728
+ this.#runners[id].runner.iteration++;
1729
+ return this.#runners[id].runner.iteration;
1730
+ } else {
1731
+ this.#warn(`#IncRunnerIterationById(): Runner ID: [${id}] not found`);
1732
+ return 0;
1750
1733
  }
1751
- });
1752
- __privateAdd(this, _GetRunnerExecutionProfileById, (id) => {
1753
- try {
1754
- if (__privateGet(this, _runners)[id]) {
1755
- return __privateGet(this, _runners)[id].runner.options.executionProfile;
1756
- } else {
1757
- __privateGet(this, _warn).call(this, `#GetRunnerExecutionProfileById(): Runner ID: [${id}] not found`);
1758
- }
1759
- } catch (error) {
1760
- __privateGet(this, _error).call(this, `#GetRunnerExecutionProfileById(): [${error}]`);
1734
+ } catch (error) {
1735
+ this.#error(`#IncRunnerIterationById(): [${error}]`);
1736
+ return 0;
1737
+ }
1738
+ };
1739
+ #GetRunnerInstanceById = (id) => {
1740
+ try {
1741
+ if (this.#runners[id]) {
1742
+ return this.#runners[id].runnerInstance;
1743
+ } else {
1744
+ this.#warn(`#GetRunnerInstanceById(): Runner ID: [${id}] not found`);
1761
1745
  }
1762
- });
1763
- __privateAdd(this, _GetRunnerOptionsById, (id) => {
1764
- try {
1765
- if (__privateGet(this, _runners)[id]) {
1766
- return __privateGet(this, _runners)[id].runner.options;
1767
- } else {
1768
- __privateGet(this, _warn).call(this, `#GetRunnerOptionsById(): Runner ID: [${id}] not found`);
1769
- }
1770
- } catch (error) {
1771
- __privateGet(this, _error).call(this, `#GetRunnerOptionsById(): [${error}]`);
1746
+ } catch (error) {
1747
+ this.#error(`#GetRunnerInstanceById(): [${error}]`);
1748
+ }
1749
+ };
1750
+ #GetRunnerExecutionProfileById = (id) => {
1751
+ try {
1752
+ if (this.#runners[id]) {
1753
+ return this.#runners[id].runner.options.executionProfile;
1754
+ } else {
1755
+ this.#warn(`#GetRunnerExecutionProfileById(): Runner ID: [${id}] not found`);
1772
1756
  }
1773
- });
1774
- __privateAdd(this, _SetRunnerOptionsById, (id, options) => {
1775
- try {
1776
- if (__privateGet(this, _runners)[id]) {
1777
- __privateGet(this, _runners)[id].runner.options = { ...options };
1778
- return __privateGet(this, _runners)[id].runner.options;
1779
- } else {
1780
- __privateGet(this, _warn).call(this, `#SetRunnerOptionsById(): Runner ID: [${id}] not found`);
1781
- }
1782
- } catch (error) {
1783
- __privateGet(this, _error).call(this, `#SetRunnerOptionsById(): [${error}]`);
1757
+ } catch (error) {
1758
+ this.#error(`#GetRunnerExecutionProfileById(): [${error}]`);
1759
+ }
1760
+ };
1761
+ #GetRunnerOptionsById = (id) => {
1762
+ try {
1763
+ if (this.#runners[id]) {
1764
+ return this.#runners[id].runner.options;
1765
+ } else {
1766
+ this.#warn(`#GetRunnerOptionsById(): Runner ID: [${id}] not found`);
1784
1767
  }
1785
- });
1786
- __privateAdd(this, _AddRunner, async (testRunnerTelemetryPayload) => {
1787
- let result;
1788
- let returnRunner;
1789
- try {
1790
- const { runner } = testRunnerTelemetryPayload;
1791
- const asyncRunnerInstance = await this.CreateAsyncRunner(testRunnerTelemetryPayload);
1792
- if (asyncRunnerInstance) {
1793
- await __privateGet(this, _CreateRunnerEx2RunState).call(this, runner, asyncRunnerInstance);
1794
- } else {
1795
- __privateGet(this, _warn).call(this, `#AddRunner(): CreateAsyncRunner not defined.`);
1796
- }
1797
- returnRunner = { ...runner };
1798
- } catch (error) {
1799
- __privateGet(this, _error).call(this, `#AddRunner(): [${error}]`);
1768
+ } catch (error) {
1769
+ this.#error(`#GetRunnerOptionsById(): [${error}]`);
1770
+ }
1771
+ };
1772
+ #SetRunnerOptionsById = (id, options) => {
1773
+ try {
1774
+ if (this.#runners[id]) {
1775
+ this.#runners[id].runner.options = { ...options };
1776
+ return this.#runners[id].runner.options;
1777
+ } else {
1778
+ this.#warn(`#SetRunnerOptionsById(): Runner ID: [${id}] not found`);
1800
1779
  }
1801
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.AddRunnerResponse, testRunnerTelemetryPayload, result);
1802
- return returnRunner;
1803
- });
1804
- __privateAdd(this, _PostMessageToWorkerManagerById, async (command, runnerId, response) => {
1805
- try {
1806
- if (__privateGet(this, _collectorCollectorPort)) {
1807
- if (__privateGet(this, _runners)[runnerId]) {
1808
- const message = {
1809
- command,
1810
- payload: {
1811
- runner: __privateGet(this, _runners)[runnerId].runner
1812
- }
1813
- };
1814
- __privateGet(this, _collectorCollectorPort).postMessage(message);
1815
- await stsutils.Sleep(0);
1816
- } else {
1817
- __privateGet(this, _warn).call(this, `#PostMessageToWorkerManagerById(): Runner: [${runnerId}] not found`);
1818
- }
1819
- }
1820
- } catch (error) {
1821
- __privateGet(this, _error).call(this, `#PostMessageToWorkerManagerById(): [${error}]`);
1780
+ } catch (error) {
1781
+ this.#error(`#SetRunnerOptionsById(): [${error}]`);
1782
+ }
1783
+ };
1784
+ #AddRunner = async (testRunnerTelemetryPayload) => {
1785
+ let result;
1786
+ let returnRunner;
1787
+ try {
1788
+ const { runner } = testRunnerTelemetryPayload;
1789
+ const asyncRunnerInstance = await this.CreateAsyncRunner(testRunnerTelemetryPayload);
1790
+ if (asyncRunnerInstance) {
1791
+ await this.#CreateRunnerEx2RunState(runner, asyncRunnerInstance);
1792
+ } else {
1793
+ this.#warn(`#AddRunner(): CreateAsyncRunner not defined.`);
1822
1794
  }
1795
+ returnRunner = { ...runner };
1796
+ } catch (error) {
1797
+ this.#error(`#AddRunner(): [${error}]`);
1798
+ }
1799
+ this.#SendRunnerCommandResponse(eIWMessageCommands.AddRunnerResponse, testRunnerTelemetryPayload, result);
1800
+ return returnRunner;
1801
+ };
1802
+ #SleepImmediate() {
1803
+ return new Promise((resolve, reject) => {
1804
+ resolve();
1823
1805
  });
1824
- __privateAdd(this, _PostRunnersToWorkerManager, async (command, messagePayload) => {
1825
- try {
1826
- if (__privateGet(this, _collectorCollectorPort)) {
1806
+ }
1807
+ #PostMessageToWorkerManagerById = async (command, runnerId, response) => {
1808
+ try {
1809
+ if (this.#collectorCollectorPort) {
1810
+ if (this.#runners[runnerId]) {
1827
1811
  const message = {
1828
- command: eIWMessageCommands.GetRunnersResponse,
1812
+ command,
1829
1813
  payload: {
1830
- messageId: messagePayload.payload.messageId,
1831
- workerId: __privateGet(this, _workerId),
1832
- runners: Object.values(__privateGet(this, _runners)).map((runnerEx) => runnerEx.runner)
1814
+ runner: this.#runners[runnerId].runner
1833
1815
  }
1834
1816
  };
1835
- __privateGet(this, _collectorCollectorPort).postMessage(message);
1817
+ this.#collectorCollectorPort.postMessage(message);
1836
1818
  await stsutils.Sleep(0);
1819
+ } else {
1820
+ this.#warn(`#PostMessageToWorkerManagerById(): Runner: [${runnerId}] not found`);
1837
1821
  }
1838
- } catch (error) {
1839
- __privateGet(this, _error).call(this, `#PostRunnersToWorkerManager(): [${error}]`);
1840
1822
  }
1841
- });
1842
- __privateAdd(this, _StartRunner, async (testRunnerTelemetryPayload) => {
1843
- var _a;
1844
- let result;
1845
- try {
1846
- const runnerId = testRunnerTelemetryPayload.runner.id;
1847
- if (__privateGet(this, _runners)[runnerId]) {
1848
- const { state } = __privateGet(this, _runners)[runnerId].runner;
1849
- if (state === IRunnerState.created) {
1850
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.StartRunner());
1851
- __privateGet(this, _UpdateRunnerStateById).call(this, "#StartRunner-1", runnerId, IRunnerState.running);
1852
- await stsutils.Sleep(0);
1853
- const startLoop = /* @__PURE__ */ new Date();
1854
- const ExecuteLoop = async () => {
1855
- var _a2, _b, _c;
1856
- try {
1857
- let cont = true;
1858
- const executionProfile = __privateGet(this, _GetRunnerExecutionProfileById).call(this, runnerId);
1859
- if (executionProfile) {
1860
- const { iterations, duration, delayBetweenIterations, pauseOnComplete } = executionProfile;
1861
- if (iterations > 0) {
1862
- cont = __privateGet(this, _GetRunnerIterationById).call(this, runnerId) < iterations;
1863
- if (cont === false && pauseOnComplete === true && __privateGet(this, _runners)[runnerId].runner.state === IRunnerState.paused) {
1864
- cont = true;
1865
- }
1866
- } else if (duration > 0) {
1867
- cont = ((/* @__PURE__ */ new Date()).getTime() - startLoop.getTime()) / 1e3 < duration;
1823
+ } catch (error) {
1824
+ this.#error(`#PostMessageToWorkerManagerById(): [${error}]`);
1825
+ }
1826
+ };
1827
+ #PostRunnersToWorkerManager = async (command, messagePayload) => {
1828
+ try {
1829
+ if (this.#collectorCollectorPort) {
1830
+ const message = {
1831
+ command: eIWMessageCommands.GetRunnersResponse,
1832
+ payload: {
1833
+ messageId: messagePayload.payload.messageId,
1834
+ workerId: this.#workerId,
1835
+ runners: Object.values(this.#runners).map((runnerEx) => runnerEx.runner)
1836
+ }
1837
+ };
1838
+ this.#collectorCollectorPort.postMessage(message);
1839
+ await stsutils.Sleep(0);
1840
+ }
1841
+ } catch (error) {
1842
+ this.#error(`#PostRunnersToWorkerManager(): [${error}]`);
1843
+ }
1844
+ };
1845
+ #StartRunner = async (testRunnerTelemetryPayload) => {
1846
+ let result;
1847
+ try {
1848
+ const runnerId = testRunnerTelemetryPayload.runner.id;
1849
+ if (this.#runners[runnerId]) {
1850
+ const { state } = this.#runners[runnerId].runner;
1851
+ if (state === IRunnerState.created) {
1852
+ result = await this.#GetRunnerInstanceById(runnerId)?.StartRunner();
1853
+ this.#UpdateRunnerStateById("#StartRunner-1", runnerId, IRunnerState.running);
1854
+ await stsutils.Sleep(0);
1855
+ const startLoop = /* @__PURE__ */ new Date();
1856
+ const ExecuteLoop = async () => {
1857
+ try {
1858
+ let cont = true;
1859
+ const executionProfile = this.#GetRunnerExecutionProfileById(runnerId);
1860
+ if (executionProfile) {
1861
+ const { iterations, duration, delayBetweenIterations, pauseOnComplete } = executionProfile;
1862
+ if (iterations > 0) {
1863
+ cont = this.#GetRunnerIterationById(runnerId) < iterations;
1864
+ if (cont === false && pauseOnComplete === true && this.#runners[runnerId].runner.state === IRunnerState.paused) {
1865
+ cont = true;
1868
1866
  }
1869
- if (cont) {
1870
- if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1871
- await ((_a2 = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a2.ExecuteRunner());
1872
- if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1873
- __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
1874
- }
1867
+ } else if (duration > 0) {
1868
+ cont = ((/* @__PURE__ */ new Date()).getTime() - startLoop.getTime()) / 1e3 < duration;
1869
+ }
1870
+ if (cont) {
1871
+ if (this.#CanExecuteNextIterationById(runnerId)) {
1872
+ await this.#GetRunnerInstanceById(runnerId)?.ExecuteRunner();
1873
+ if (!this.#IsCompletedById(runnerId)) {
1874
+ this.#IncRunnerIterationById(runnerId);
1875
1875
  }
1876
- if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1877
- if (delayBetweenIterations > 0) {
1878
- await stsutils.Sleep(delayBetweenIterations);
1879
- } else {
1880
- await __privateMethod(this, _WorkerInstance_instances, SleepImmediate_fn).call(this);
1881
- }
1882
- ExecuteLoop();
1876
+ }
1877
+ if (this.#CanExecuteNextIterationById(runnerId)) {
1878
+ if (delayBetweenIterations > 0) {
1879
+ await stsutils.Sleep(delayBetweenIterations);
1883
1880
  } else {
1884
- if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1885
- await stsutils.Sleep(50);
1886
- ExecuteLoop();
1887
- }
1881
+ await this.#SleepImmediate();
1888
1882
  }
1883
+ ExecuteLoop();
1889
1884
  } else {
1890
- if (pauseOnComplete === true) {
1891
- await ((_b = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _b.PauseRunner());
1892
- __privateGet(this, _UpdateRunnerStateById).call(this, "#StartRunner-2", runnerId, IRunnerState.paused);
1885
+ if (!this.#IsCompletedById(runnerId)) {
1886
+ await stsutils.Sleep(50);
1893
1887
  ExecuteLoop();
1894
- } else {
1895
- await ((_c = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _c.Completed());
1896
- __privateGet(this, _UpdateRunnerStateById).call(this, "#StartRunner-3", runnerId, IRunnerState.completed);
1897
1888
  }
1898
1889
  }
1899
1890
  } else {
1900
- __privateGet(this, _warn).call(this, `#StartRunner:ExecuteLoop(): Cannot get execution profile for runner: [${runnerId}]`);
1891
+ if (pauseOnComplete === true) {
1892
+ await this.#GetRunnerInstanceById(runnerId)?.PauseRunner();
1893
+ this.#UpdateRunnerStateById("#StartRunner-2", runnerId, IRunnerState.paused);
1894
+ ExecuteLoop();
1895
+ } else {
1896
+ await this.#GetRunnerInstanceById(runnerId)?.Completed();
1897
+ this.#UpdateRunnerStateById("#StartRunner-3", runnerId, IRunnerState.completed);
1898
+ }
1901
1899
  }
1902
- } catch (error) {
1903
- __privateGet(this, _error).call(this, `#StartRunner:ExecuteLoop(): Error: [${error}]`);
1900
+ } else {
1901
+ this.#warn(`#StartRunner:ExecuteLoop(): Cannot get execution profile for runner: [${runnerId}]`);
1904
1902
  }
1905
- };
1906
- ExecuteLoop();
1907
- }
1908
- } else {
1909
- __privateGet(this, _warn).call(this, `#StartRunner(): Runner: [${runnerId}] not found`);
1903
+ } catch (error) {
1904
+ this.#error(`#StartRunner:ExecuteLoop(): Error: [${error}]`);
1905
+ }
1906
+ };
1907
+ ExecuteLoop();
1910
1908
  }
1911
- } catch (error) {
1912
- __privateGet(this, _error).call(this, `#StartRunner(): Error: [${error}]`);
1909
+ } else {
1910
+ this.#warn(`#StartRunner(): Runner: [${runnerId}] not found`);
1913
1911
  }
1914
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.StartRunnerResponse, testRunnerTelemetryPayload, result);
1915
- });
1916
- __privateAdd(this, _StopRunnerByRunnerId, async (id) => {
1917
- var _a;
1918
- let retVal;
1919
- try {
1920
- if (__privateGet(this, _runners)[id]) {
1921
- const { state } = __privateGet(this, _runners)[id].runner;
1922
- if (state === IRunnerState.paused || state === IRunnerState.running) {
1923
- retVal = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, id)) == null ? void 0 : _a.StopRunner());
1924
- __privateGet(this, _UpdateRunnerStateById).call(this, "#StopRunnerByRunnerId", id, IRunnerState.stopped);
1925
- }
1926
- } else {
1927
- __privateGet(this, _warn).call(this, `#StopRunnerByRunnerId(): Runner: [${id}] not found`);
1912
+ } catch (error) {
1913
+ this.#error(`#StartRunner(): Error: [${error}]`);
1914
+ }
1915
+ this.#SendRunnerCommandResponse(eIWMessageCommands.StartRunnerResponse, testRunnerTelemetryPayload, result);
1916
+ };
1917
+ #StopRunnerByRunnerId = async (id) => {
1918
+ let retVal;
1919
+ try {
1920
+ if (this.#runners[id]) {
1921
+ const { state } = this.#runners[id].runner;
1922
+ if (state === IRunnerState.paused || state === IRunnerState.running) {
1923
+ retVal = await this.#GetRunnerInstanceById(id)?.StopRunner();
1924
+ this.#UpdateRunnerStateById("#StopRunnerByRunnerId", id, IRunnerState.stopped);
1928
1925
  }
1929
- } catch (error) {
1930
- __privateGet(this, _error).call(this, `#StopRunnerByRunnerId(): Error: [${error}]`);
1926
+ } else {
1927
+ this.#warn(`#StopRunnerByRunnerId(): Runner: [${id}] not found`);
1931
1928
  }
1932
- return retVal;
1933
- });
1934
- __privateAdd(this, _StopRunner, async (testRunnerTelemetryPayload) => {
1935
- let result;
1936
- try {
1937
- result = await __privateGet(this, _StopRunnerByRunnerId).call(this, testRunnerTelemetryPayload.runner.id);
1938
- } catch (error) {
1939
- __privateGet(this, _error).call(this, `#StopRunner(): Error: [${error}]`);
1940
- }
1941
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.StopRunnerResponse, testRunnerTelemetryPayload, result);
1942
- });
1943
- __privateAdd(this, _TerminateRunner, async (testRunnerTelemetryPayload) => {
1944
- var _a;
1945
- let result;
1946
- try {
1947
- const runnerId = testRunnerTelemetryPayload.runner.id;
1948
- if (__privateGet(this, _runners)[runnerId]) {
1949
- const { state } = __privateGet(this, _runners)[runnerId].runner;
1950
- if (state === IRunnerState.created || state === IRunnerState.paused || state === IRunnerState.running) {
1951
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.TerminateRunner());
1952
- __privateGet(this, _UpdateRunnerStateById).call(this, "#TerminateRunner", runnerId, IRunnerState.terminated);
1953
- }
1954
- } else {
1955
- __privateGet(this, _warn).call(this, `#TerminateRunner(): Runner: [${runnerId}] not found`);
1929
+ } catch (error) {
1930
+ this.#error(`#StopRunnerByRunnerId(): Error: [${error}]`);
1931
+ }
1932
+ return retVal;
1933
+ };
1934
+ #StopRunner = async (testRunnerTelemetryPayload) => {
1935
+ let result;
1936
+ try {
1937
+ result = await this.#StopRunnerByRunnerId(testRunnerTelemetryPayload.runner.id);
1938
+ } catch (error) {
1939
+ this.#error(`#StopRunner(): Error: [${error}]`);
1940
+ }
1941
+ this.#SendRunnerCommandResponse(eIWMessageCommands.StopRunnerResponse, testRunnerTelemetryPayload, result);
1942
+ };
1943
+ #TerminateRunner = async (testRunnerTelemetryPayload) => {
1944
+ let result;
1945
+ try {
1946
+ const runnerId = testRunnerTelemetryPayload.runner.id;
1947
+ if (this.#runners[runnerId]) {
1948
+ const { state } = this.#runners[runnerId].runner;
1949
+ if (state === IRunnerState.created || state === IRunnerState.paused || state === IRunnerState.running) {
1950
+ result = await this.#GetRunnerInstanceById(runnerId)?.TerminateRunner();
1951
+ this.#UpdateRunnerStateById("#TerminateRunner", runnerId, IRunnerState.terminated);
1956
1952
  }
1957
- } catch (error) {
1958
- __privateGet(this, _error).call(this, `#TerminateRunner(): Error: [${error}]`);
1953
+ } else {
1954
+ this.#warn(`#TerminateRunner(): Runner: [${runnerId}] not found`);
1959
1955
  }
1960
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.TerminateRunnerResponse, testRunnerTelemetryPayload, result);
1961
- });
1962
- __privateAdd(this, _SendRunnerCommandResponse, (command, testRunnerTelemetryPayload, result) => {
1963
- try {
1964
- let runner = void 0;
1965
- const runnerId = testRunnerTelemetryPayload.runner.id;
1966
- if (__privateGet(this, _runners)[runnerId]) {
1967
- runner = { ...__privateGet(this, _runners)[runnerId].runner };
1968
- }
1969
- if (__privateGet(this, _collectorCollectorPort)) {
1970
- const message = {
1971
- command,
1972
- payload: {
1973
- messageId: testRunnerTelemetryPayload.messageId,
1974
- runner,
1975
- executeRunnerActionResult: {
1976
- workerManagerId: testRunnerTelemetryPayload.runner.workerManagerId,
1977
- workerId: testRunnerTelemetryPayload.runner.workerId,
1978
- runnerId: testRunnerTelemetryPayload.runner.id,
1979
- result
1980
- }
1956
+ } catch (error) {
1957
+ this.#error(`#TerminateRunner(): Error: [${error}]`);
1958
+ }
1959
+ this.#SendRunnerCommandResponse(eIWMessageCommands.TerminateRunnerResponse, testRunnerTelemetryPayload, result);
1960
+ };
1961
+ #SendRunnerCommandResponse = (command, testRunnerTelemetryPayload, result) => {
1962
+ try {
1963
+ let runner = void 0;
1964
+ const runnerId = testRunnerTelemetryPayload.runner.id;
1965
+ if (this.#runners[runnerId]) {
1966
+ runner = { ...this.#runners[runnerId].runner };
1967
+ }
1968
+ if (this.#collectorCollectorPort) {
1969
+ const message = {
1970
+ command,
1971
+ payload: {
1972
+ messageId: testRunnerTelemetryPayload.messageId,
1973
+ runner,
1974
+ executeRunnerActionResult: {
1975
+ workerManagerId: testRunnerTelemetryPayload.runner.workerManagerId,
1976
+ workerId: testRunnerTelemetryPayload.runner.workerId,
1977
+ runnerId: testRunnerTelemetryPayload.runner.id,
1978
+ result
1981
1979
  }
1982
- };
1983
- __privateGet(this, _collectorCollectorPort).postMessage(message);
1984
- }
1985
- } catch (error) {
1986
- __privateGet(this, _error).call(this, `#SendRunnerCommandResponse(): [${error}]`);
1987
- }
1988
- });
1989
- __privateAdd(this, _PauseRunner, async (testRunnerTelemetryPayload) => {
1990
- var _a;
1991
- let result;
1992
- try {
1993
- const runnerId = testRunnerTelemetryPayload.runner.id;
1994
- if (__privateGet(this, _runners)[runnerId]) {
1995
- const { state } = __privateGet(this, _runners)[runnerId].runner;
1996
- if (state === IRunnerState.running) {
1997
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.PauseRunner());
1998
- __privateGet(this, _UpdateRunnerStateById).call(this, "#PauseRunner", runnerId, IRunnerState.paused);
1999
1980
  }
2000
- } else {
2001
- __privateGet(this, _warn).call(this, `#PauseRunner(): Runner: [${runnerId}] not found`);
2002
- }
2003
- } catch (error) {
2004
- __privateGet(this, _error).call(this, `#PauseRunner(): Error: [${error}]`);
1981
+ };
1982
+ this.#collectorCollectorPort.postMessage(message);
2005
1983
  }
2006
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.PauseRunnerResponse, testRunnerTelemetryPayload, result);
2007
- });
2008
- __privateAdd(this, _ResumeRunner, async (testRunnerTelemetryPayload) => {
2009
- var _a;
2010
- let result;
2011
- try {
2012
- const runnerId = testRunnerTelemetryPayload.runner.id;
2013
- if (__privateGet(this, _runners)[runnerId]) {
2014
- const { state } = __privateGet(this, _runners)[runnerId].runner;
2015
- if (state === IRunnerState.paused) {
2016
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResumeRunner());
2017
- __privateGet(this, _UpdateRunnerStateById).call(this, "#ResumeRunner", runnerId, IRunnerState.running);
2018
- }
2019
- } else {
2020
- __privateGet(this, _warn).call(this, `#ResumeRunner(): Runner: [${runnerId}] not found`);
1984
+ } catch (error) {
1985
+ this.#error(`#SendRunnerCommandResponse(): [${error}]`);
1986
+ }
1987
+ };
1988
+ #PauseRunner = async (testRunnerTelemetryPayload) => {
1989
+ let result;
1990
+ try {
1991
+ const runnerId = testRunnerTelemetryPayload.runner.id;
1992
+ if (this.#runners[runnerId]) {
1993
+ const { state } = this.#runners[runnerId].runner;
1994
+ if (state === IRunnerState.running) {
1995
+ result = await this.#GetRunnerInstanceById(runnerId)?.PauseRunner();
1996
+ this.#UpdateRunnerStateById("#PauseRunner", runnerId, IRunnerState.paused);
2021
1997
  }
2022
- } catch (error) {
2023
- __privateGet(this, _error).call(this, `#ResumeRunner(): Error: [${error}]`);
1998
+ } else {
1999
+ this.#warn(`#PauseRunner(): Runner: [${runnerId}] not found`);
2024
2000
  }
2025
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.ResumeRunnerResponse, testRunnerTelemetryPayload, result);
2026
- });
2027
- __privateAdd(this, _ResetRunner, async (testRunnerTelemetryPayload) => {
2028
- var _a;
2029
- let result;
2030
- try {
2031
- const runnerId = testRunnerTelemetryPayload.runner.id;
2032
- if (__privateGet(this, _runners)[runnerId]) {
2033
- const { state } = __privateGet(this, _runners)[runnerId].runner;
2034
- if (state === IRunnerState.paused || state === IRunnerState.running) {
2035
- __privateGet(this, _UpdateRunnerStateById).call(this, "#ResetRunner", runnerId, IRunnerState.paused);
2036
- __privateGet(this, _ResetRunnerIterationById).call(this, runnerId);
2037
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResetRunner());
2038
- }
2039
- } else {
2040
- __privateGet(this, _warn).call(this, `#ResetRunner(): Runner: [${runnerId}] not found`);
2001
+ } catch (error) {
2002
+ this.#error(`#PauseRunner(): Error: [${error}]`);
2003
+ }
2004
+ this.#SendRunnerCommandResponse(eIWMessageCommands.PauseRunnerResponse, testRunnerTelemetryPayload, result);
2005
+ };
2006
+ #ResumeRunner = async (testRunnerTelemetryPayload) => {
2007
+ let result;
2008
+ try {
2009
+ const runnerId = testRunnerTelemetryPayload.runner.id;
2010
+ if (this.#runners[runnerId]) {
2011
+ const { state } = this.#runners[runnerId].runner;
2012
+ if (state === IRunnerState.paused) {
2013
+ result = await this.#GetRunnerInstanceById(runnerId)?.ResumeRunner();
2014
+ this.#UpdateRunnerStateById("#ResumeRunner", runnerId, IRunnerState.running);
2041
2015
  }
2042
- } catch (error) {
2043
- __privateGet(this, _error).call(this, `#ResetRunner(): Error: [${error}]`);
2016
+ } else {
2017
+ this.#warn(`#ResumeRunner(): Runner: [${runnerId}] not found`);
2044
2018
  }
2045
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.ResetRunnerResponse, testRunnerTelemetryPayload, result);
2046
- });
2047
- // Execute a single iteration of this runners work item
2048
- __privateAdd(this, _ExecuteRunner, async (testRunnerTelemetryPayload) => {
2049
- var _a;
2050
- let result;
2051
- try {
2052
- const runnerId = testRunnerTelemetryPayload.runner.id;
2053
- if (__privateGet(this, _runners)[runnerId]) {
2054
- const { state } = __privateGet(this, _runners)[runnerId].runner;
2055
- if (state === IRunnerState.paused || state === IRunnerState.created) {
2056
- const currentIteration = __privateGet(this, _GetRunnerIterationById).call(this, runnerId);
2057
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} ExecuteRunner(${currentIteration})`);
2058
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ExecuteRunner());
2059
- const newIteration = __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
2060
- __privateGet(this, _debug).call(this, `${chalk.magenta(` --> runner: [${runnerId}]`)} Next iteration number: [${newIteration}] for next Execute or Resume.`);
2061
- __privateGet(this, _UpdateRunnerStateById).call(this, "#ExecuteRunner", runnerId, IRunnerState.paused);
2062
- }
2063
- } else {
2064
- __privateGet(this, _warn).call(this, `#ExecuteRunner(): Runner: [${runnerId}] not found`);
2019
+ } catch (error) {
2020
+ this.#error(`#ResumeRunner(): Error: [${error}]`);
2021
+ }
2022
+ this.#SendRunnerCommandResponse(eIWMessageCommands.ResumeRunnerResponse, testRunnerTelemetryPayload, result);
2023
+ };
2024
+ #ResetRunner = async (testRunnerTelemetryPayload) => {
2025
+ let result;
2026
+ try {
2027
+ const runnerId = testRunnerTelemetryPayload.runner.id;
2028
+ if (this.#runners[runnerId]) {
2029
+ const { state } = this.#runners[runnerId].runner;
2030
+ if (state === IRunnerState.paused || state === IRunnerState.running) {
2031
+ this.#UpdateRunnerStateById("#ResetRunner", runnerId, IRunnerState.paused);
2032
+ this.#ResetRunnerIterationById(runnerId);
2033
+ result = await this.#GetRunnerInstanceById(runnerId)?.ResetRunner();
2065
2034
  }
2066
- } catch (error) {
2067
- __privateGet(this, _error).call(this, `#ExecuteRunner(): Error: [${error}]`);
2035
+ } else {
2036
+ this.#warn(`#ResetRunner(): Runner: [${runnerId}] not found`);
2068
2037
  }
2069
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.ExecuteRunnerResponse, testRunnerTelemetryPayload, result);
2070
- });
2071
- __privateAdd(this, _UpdateRunner, async (testRunnerTelemetryPayload) => {
2072
- var _a;
2073
- let result;
2074
- try {
2075
- const runnerId = testRunnerTelemetryPayload.runner.id;
2076
- if (__privateGet(this, _runners)[runnerId]) {
2077
- const { state } = __privateGet(this, _runners)[runnerId].runner;
2078
- if (state === IRunnerState.paused || state === IRunnerState.created || state === IRunnerState.running) {
2079
- __privateGet(this, _debug).call(this, chalk.cyan(`before: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
2080
- __privateGet(this, _SetRunnerOptionsById).call(this, runnerId, testRunnerTelemetryPayload.runner.options);
2081
- __privateGet(this, _debug).call(this, chalk.cyan(`after: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
2082
- result = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.UpdateRunner(testRunnerTelemetryPayload.runner.options));
2083
- }
2084
- } else {
2085
- __privateGet(this, _warn).call(this, `#UpdateRunner(): Runner: [${runnerId}] not found`);
2038
+ } catch (error) {
2039
+ this.#error(`#ResetRunner(): Error: [${error}]`);
2040
+ }
2041
+ this.#SendRunnerCommandResponse(eIWMessageCommands.ResetRunnerResponse, testRunnerTelemetryPayload, result);
2042
+ };
2043
+ // Execute a single iteration of this runners work item
2044
+ #ExecuteRunner = async (testRunnerTelemetryPayload) => {
2045
+ let result;
2046
+ try {
2047
+ const runnerId = testRunnerTelemetryPayload.runner.id;
2048
+ if (this.#runners[runnerId]) {
2049
+ const { state } = this.#runners[runnerId].runner;
2050
+ if (state === IRunnerState.paused || state === IRunnerState.created) {
2051
+ const currentIteration = this.#GetRunnerIterationById(runnerId);
2052
+ this.#debug(`${chalk.magenta(`runner: [${runnerId}]`)} ExecuteRunner(${currentIteration})`);
2053
+ result = await this.#GetRunnerInstanceById(runnerId)?.ExecuteRunner();
2054
+ const newIteration = this.#IncRunnerIterationById(runnerId);
2055
+ this.#debug(`${chalk.magenta(` --> runner: [${runnerId}]`)} Next iteration number: [${newIteration}] for next Execute or Resume.`);
2056
+ this.#UpdateRunnerStateById("#ExecuteRunner", runnerId, IRunnerState.paused);
2086
2057
  }
2087
- } catch (error) {
2088
- __privateGet(this, _error).call(this, `#UpdateRunner(): Error: [${error}]`);
2058
+ } else {
2059
+ this.#warn(`#ExecuteRunner(): Runner: [${runnerId}] not found`);
2089
2060
  }
2090
- __privateGet(this, _SendRunnerCommandResponse).call(this, eIWMessageCommands.UpdateRunnerResponse, testRunnerTelemetryPayload, result);
2091
- });
2092
- // ProcessMessage = async(data: MessageEvent) => { // Browser version
2093
- __publicField(this, "ProcessMessage", async (data) => {
2094
- __privateGet(this, _silly).call(this, `ProcessMessage: data: [${JSON.stringify(data)}]`);
2095
- try {
2096
- const payloadMessage = data;
2097
- switch (payloadMessage.command) {
2098
- case eIWMessageCommands.MessagePort:
2099
- __privateGet(this, _silly).call(this, `ProcessMessage::MessagePort`);
2100
- __privateGet(this, _SetMessagePort).call(this, payloadMessage.payload);
2101
- __privateSet(this, _options, payloadMessage.payload.options);
2102
- __privateSet(this, _workerId, payloadMessage.payload.workerId);
2103
- __privateGet(this, _debug).call(this, `ProcessMessage::#workerId: [${__privateGet(this, _workerId)}]`);
2104
- __privateGet(this, _debug).call(this, `ProcessMessage::#options: [${JSON.stringify(__privateGet(this, _options))}]`);
2105
- break;
2106
- case eIWMessageCommands.AddRunner:
2107
- __privateGet(this, _silly).call(this, `ProcessMessage::AddRunner`);
2108
- __privateGet(this, _AddRunner).call(this, payloadMessage.payload);
2109
- break;
2110
- case eIWMessageCommands.StartRunner:
2111
- __privateGet(this, _silly).call(this, `ProcessMessage::StartRunner`);
2112
- __privateGet(this, _StartRunner).call(this, payloadMessage.payload);
2113
- break;
2114
- case eIWMessageCommands.StopRunner:
2115
- __privateGet(this, _silly).call(this, `ProcessMessage::StopRunner`);
2116
- __privateGet(this, _StopRunner).call(this, payloadMessage.payload);
2117
- break;
2118
- case eIWMessageCommands.TerminateRunner:
2119
- __privateGet(this, _silly).call(this, `ProcessMessage::TerminateRunner`);
2120
- __privateGet(this, _TerminateRunner).call(this, payloadMessage.payload);
2121
- break;
2122
- case eIWMessageCommands.PauseRunner:
2123
- __privateGet(this, _silly).call(this, `ProcessMessage::PauseRunner`);
2124
- __privateGet(this, _PauseRunner).call(this, payloadMessage.payload);
2125
- break;
2126
- case eIWMessageCommands.ResumeRunner:
2127
- __privateGet(this, _silly).call(this, `ProcessMessage::ResumeRunner`);
2128
- __privateGet(this, _ResumeRunner).call(this, payloadMessage.payload);
2129
- break;
2130
- case eIWMessageCommands.ResetRunner:
2131
- __privateGet(this, _silly).call(this, `ProcessMessage::ResetRunner`);
2132
- __privateGet(this, _ResetRunner).call(this, payloadMessage.payload);
2133
- break;
2134
- case eIWMessageCommands.ExecuteRunner:
2135
- __privateGet(this, _silly).call(this, `ProcessMessage::ExecuteRunner`);
2136
- __privateGet(this, _ExecuteRunner).call(this, payloadMessage.payload);
2137
- break;
2138
- case eIWMessageCommands.UpdateRunner:
2139
- __privateGet(this, _silly).call(this, `ProcessMessage::UpdateRunner`);
2140
- __privateGet(this, _UpdateRunner).call(this, payloadMessage.payload);
2141
- break;
2142
- case eIWMessageCommands.GetRunners:
2143
- __privateGet(this, _silly).call(this, `ProcessMessage::GetRunners`);
2144
- __privateGet(this, _PostRunnersToWorkerManager).call(this, eIWMessageCommands.GetRunners, payloadMessage);
2145
- break;
2146
- default:
2147
- __privateGet(this, _warn).call(this, `ProcessMessage::default: Invalid payloadMessage.command: [${payloadMessage.command}] - Ignoring`);
2061
+ } catch (error) {
2062
+ this.#error(`#ExecuteRunner(): Error: [${error}]`);
2063
+ }
2064
+ this.#SendRunnerCommandResponse(eIWMessageCommands.ExecuteRunnerResponse, testRunnerTelemetryPayload, result);
2065
+ };
2066
+ #UpdateRunner = async (testRunnerTelemetryPayload) => {
2067
+ let result;
2068
+ try {
2069
+ const runnerId = testRunnerTelemetryPayload.runner.id;
2070
+ if (this.#runners[runnerId]) {
2071
+ const { state } = this.#runners[runnerId].runner;
2072
+ if (state === IRunnerState.paused || state === IRunnerState.created || state === IRunnerState.running) {
2073
+ this.#debug(chalk.cyan(`before: [${JSON.stringify(this.#GetRunnerOptionsById(runnerId))}]`));
2074
+ this.#SetRunnerOptionsById(runnerId, testRunnerTelemetryPayload.runner.options);
2075
+ this.#debug(chalk.cyan(`after: [${JSON.stringify(this.#GetRunnerOptionsById(runnerId))}]`));
2076
+ result = await this.#GetRunnerInstanceById(runnerId)?.UpdateRunner(testRunnerTelemetryPayload.runner.options);
2148
2077
  }
2149
- } catch (error) {
2150
- __privateGet(this, _error).call(this, `ProcessMessage(): Error: [${error}]`);
2151
- __privateGet(this, _error).call(this, error);
2078
+ } else {
2079
+ this.#warn(`#UpdateRunner(): Runner: [${runnerId}] not found`);
2152
2080
  }
2153
- });
2154
- __privateGet(this, _processLoopExecutor).call(this);
2155
- }
2156
- get logger() {
2157
- return stsutils.defaultLogger;
2158
- }
2159
- get CollectorCollectorPort() {
2160
- return __privateGet(this, _collectorCollectorPort);
2161
- }
2162
- get Options() {
2163
- return __privateGet(this, _options);
2164
- }
2081
+ } catch (error) {
2082
+ this.#error(`#UpdateRunner(): Error: [${error}]`);
2083
+ }
2084
+ this.#SendRunnerCommandResponse(eIWMessageCommands.UpdateRunnerResponse, testRunnerTelemetryPayload, result);
2085
+ };
2086
+ // ProcessMessage = async(data: MessageEvent) => { // Browser version
2087
+ ProcessMessage = async (data) => {
2088
+ this.#silly(`ProcessMessage: data: [${JSON.stringify(data)}]`);
2089
+ try {
2090
+ const payloadMessage = data;
2091
+ switch (payloadMessage.command) {
2092
+ case eIWMessageCommands.MessagePort:
2093
+ this.#silly(`ProcessMessage::MessagePort`);
2094
+ this.#SetMessagePort(payloadMessage.payload);
2095
+ this.#options = payloadMessage.payload.options;
2096
+ this.#workerId = payloadMessage.payload.workerId;
2097
+ this.#debug(`ProcessMessage::#workerId: [${this.#workerId}]`);
2098
+ this.#debug(`ProcessMessage::#options: [${JSON.stringify(this.#options)}]`);
2099
+ break;
2100
+ case eIWMessageCommands.AddRunner:
2101
+ this.#silly(`ProcessMessage::AddRunner`);
2102
+ this.#AddRunner(payloadMessage.payload);
2103
+ break;
2104
+ case eIWMessageCommands.StartRunner:
2105
+ this.#silly(`ProcessMessage::StartRunner`);
2106
+ this.#StartRunner(payloadMessage.payload);
2107
+ break;
2108
+ case eIWMessageCommands.StopRunner:
2109
+ this.#silly(`ProcessMessage::StopRunner`);
2110
+ this.#StopRunner(payloadMessage.payload);
2111
+ break;
2112
+ case eIWMessageCommands.TerminateRunner:
2113
+ this.#silly(`ProcessMessage::TerminateRunner`);
2114
+ this.#TerminateRunner(payloadMessage.payload);
2115
+ break;
2116
+ case eIWMessageCommands.PauseRunner:
2117
+ this.#silly(`ProcessMessage::PauseRunner`);
2118
+ this.#PauseRunner(payloadMessage.payload);
2119
+ break;
2120
+ case eIWMessageCommands.ResumeRunner:
2121
+ this.#silly(`ProcessMessage::ResumeRunner`);
2122
+ this.#ResumeRunner(payloadMessage.payload);
2123
+ break;
2124
+ case eIWMessageCommands.ResetRunner:
2125
+ this.#silly(`ProcessMessage::ResetRunner`);
2126
+ this.#ResetRunner(payloadMessage.payload);
2127
+ break;
2128
+ case eIWMessageCommands.ExecuteRunner:
2129
+ this.#silly(`ProcessMessage::ExecuteRunner`);
2130
+ this.#ExecuteRunner(payloadMessage.payload);
2131
+ break;
2132
+ case eIWMessageCommands.UpdateRunner:
2133
+ this.#silly(`ProcessMessage::UpdateRunner`);
2134
+ this.#UpdateRunner(payloadMessage.payload);
2135
+ break;
2136
+ case eIWMessageCommands.GetRunners:
2137
+ this.#silly(`ProcessMessage::GetRunners`);
2138
+ this.#PostRunnersToWorkerManager(eIWMessageCommands.GetRunners, payloadMessage);
2139
+ break;
2140
+ default:
2141
+ this.#warn(`ProcessMessage::default: Invalid payloadMessage.command: [${payloadMessage.command}] - Ignoring`);
2142
+ }
2143
+ } catch (error) {
2144
+ this.#error(`ProcessMessage(): Error: [${error}]`);
2145
+ this.#error(error);
2146
+ }
2147
+ };
2165
2148
  }
2166
- _collectorCollectorPort = new WeakMap();
2167
- _runners = new WeakMap();
2168
- _options = new WeakMap();
2169
- _workerId = new WeakMap();
2170
- _archiveDeleteTimeout = new WeakMap();
2171
- _logMessage = new WeakMap();
2172
- _silly = new WeakMap();
2173
- _debug = new WeakMap();
2174
- _info = new WeakMap();
2175
- _warn = new WeakMap();
2176
- _error = new WeakMap();
2177
- _processLoopExecutor = new WeakMap();
2178
- _SetMessagePort = new WeakMap();
2179
- _CreateRunnerEx2RunState = new WeakMap();
2180
- _UpdateRunnerStateById = new WeakMap();
2181
- _CanExecuteNextIterationById = new WeakMap();
2182
- _IsCompletedById = new WeakMap();
2183
- _GetRunnerIterationById = new WeakMap();
2184
- _ResetRunnerIterationById = new WeakMap();
2185
- _IncRunnerIterationById = new WeakMap();
2186
- _GetRunnerInstanceById = new WeakMap();
2187
- _GetRunnerExecutionProfileById = new WeakMap();
2188
- _GetRunnerOptionsById = new WeakMap();
2189
- _SetRunnerOptionsById = new WeakMap();
2190
- _AddRunner = new WeakMap();
2191
- _WorkerInstance_instances = new WeakSet();
2192
- SleepImmediate_fn = function() {
2193
- return new Promise((resolve, reject) => {
2194
- resolve();
2195
- });
2196
- };
2197
- _PostMessageToWorkerManagerById = new WeakMap();
2198
- _PostRunnersToWorkerManager = new WeakMap();
2199
- _StartRunner = new WeakMap();
2200
- _StopRunnerByRunnerId = new WeakMap();
2201
- _StopRunner = new WeakMap();
2202
- _TerminateRunner = new WeakMap();
2203
- _SendRunnerCommandResponse = new WeakMap();
2204
- _PauseRunner = new WeakMap();
2205
- _ResumeRunner = new WeakMap();
2206
- _ResetRunner = new WeakMap();
2207
- _ExecuteRunner = new WeakMap();
2208
- _UpdateRunner = new WeakMap();
2209
2149
  class TelemetryProcessor {
2210
- constructor() {
2211
- __publicField(this, "ProcessTelemetry", (publishInstrumentController, telemetry) => {
2212
- let update = false;
2213
- if (telemetry.message) {
2214
- telemetry.message.forEach((message) => {
2215
- publishInstrumentController.LogEx(message);
2216
- });
2217
- update = true;
2218
- }
2219
- if (telemetry.requestCount) {
2220
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.REQUEST_COUNT_GAUGE, {
2221
- val: telemetry.requestCount
2222
- });
2223
- update = true;
2224
- }
2225
- if (telemetry.errorCount) {
2226
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.ERROR_COUNT_GAUGE, {
2227
- val: telemetry.errorCount
2228
- });
2229
- update = true;
2230
- }
2231
- if (telemetry.retryCount) {
2232
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.RETRY_COUNT_GAUGE, {
2233
- val: telemetry.retryCount
2234
- });
2235
- update = true;
2236
- }
2237
- if (telemetry.authenticationCount) {
2238
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_COUNT_GAUGE, {
2239
- val: telemetry.authenticationCount
2240
- });
2241
- update = true;
2242
- }
2243
- if (telemetry.authenticationErrorCount) {
2244
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, {
2245
- val: telemetry.authenticationErrorCount
2246
- });
2247
- update = true;
2248
- }
2249
- if (telemetry.authenticationRetryCount) {
2250
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, {
2251
- val: telemetry.authenticationRetryCount
2252
- });
2253
- update = true;
2254
- }
2255
- if (telemetry.coreCount) {
2256
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.CORE_COUNT_GAUGE, {
2257
- val: telemetry.coreCount
2258
- });
2259
- update = true;
2260
- }
2261
- if (telemetry.timer) {
2262
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.TIMER_GAUGE, {
2263
- val: telemetry.timer
2264
- });
2265
- update = true;
2266
- }
2267
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.ACTIVE_REQUEST_GAUGE, {
2268
- val: telemetry.activeRequestCount
2150
+ ProcessTelemetry = (publishInstrumentController, telemetry) => {
2151
+ let update = false;
2152
+ if (telemetry.message) {
2153
+ telemetry.message.forEach((message) => {
2154
+ publishInstrumentController.LogEx(message);
2269
2155
  });
2270
- if (telemetry.velocity) {
2271
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.VELOCITY_GAUGE, {
2272
- Inc: telemetry.velocity
2273
- });
2274
- update = true;
2275
- }
2276
- if (telemetry.duration) {
2277
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.DURATION_GAUGE, {
2278
- val: telemetry.duration
2279
- });
2280
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.DURATION_HISTOGRAM_GAUGE, {
2281
- val: telemetry.duration
2282
- });
2283
- update = true;
2284
- }
2285
- if (telemetry.latency) {
2286
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.LATENCY_GAUGE, {
2287
- val: telemetry.latency
2288
- });
2289
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.LATENCY_HISTOGRAM_GAUGE, {
2290
- val: telemetry.latency
2291
- });
2292
- update = true;
2293
- }
2294
- if (telemetry.childCount) {
2295
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.CHILD_COUNT, {
2296
- val: telemetry.childCount
2297
- });
2298
- update = true;
2299
- }
2300
- if (telemetry.rx) {
2301
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.NETWORK_RX_GAUGE, {
2302
- Inc: telemetry.rx
2303
- });
2304
- update = true;
2305
- }
2306
- if (telemetry.tx) {
2307
- publishInstrumentController.UpdateInstrument(stsobservability.Gauge.NETWORK_TX_GAUGE, {
2308
- Inc: telemetry.tx
2309
- });
2310
- update = true;
2311
- }
2312
- return update;
2156
+ update = true;
2157
+ }
2158
+ if (telemetry.requestCount) {
2159
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.REQUEST_COUNT_GAUGE, {
2160
+ val: telemetry.requestCount
2161
+ });
2162
+ update = true;
2163
+ }
2164
+ if (telemetry.errorCount) {
2165
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.ERROR_COUNT_GAUGE, {
2166
+ val: telemetry.errorCount
2167
+ });
2168
+ update = true;
2169
+ }
2170
+ if (telemetry.retryCount) {
2171
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.RETRY_COUNT_GAUGE, {
2172
+ val: telemetry.retryCount
2173
+ });
2174
+ update = true;
2175
+ }
2176
+ if (telemetry.authenticationCount) {
2177
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_COUNT_GAUGE, {
2178
+ val: telemetry.authenticationCount
2179
+ });
2180
+ update = true;
2181
+ }
2182
+ if (telemetry.authenticationErrorCount) {
2183
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, {
2184
+ val: telemetry.authenticationErrorCount
2185
+ });
2186
+ update = true;
2187
+ }
2188
+ if (telemetry.authenticationRetryCount) {
2189
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, {
2190
+ val: telemetry.authenticationRetryCount
2191
+ });
2192
+ update = true;
2193
+ }
2194
+ if (telemetry.coreCount) {
2195
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.CORE_COUNT_GAUGE, {
2196
+ val: telemetry.coreCount
2197
+ });
2198
+ update = true;
2199
+ }
2200
+ if (telemetry.timer) {
2201
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.TIMER_GAUGE, {
2202
+ val: telemetry.timer
2203
+ });
2204
+ update = true;
2205
+ }
2206
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.ACTIVE_REQUEST_GAUGE, {
2207
+ val: telemetry.activeRequestCount
2313
2208
  });
2314
- }
2209
+ if (telemetry.velocity) {
2210
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.VELOCITY_GAUGE, {
2211
+ Inc: telemetry.velocity
2212
+ });
2213
+ update = true;
2214
+ }
2215
+ if (telemetry.duration) {
2216
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.DURATION_GAUGE, {
2217
+ val: telemetry.duration
2218
+ });
2219
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.DURATION_HISTOGRAM_GAUGE, {
2220
+ val: telemetry.duration
2221
+ });
2222
+ update = true;
2223
+ }
2224
+ if (telemetry.latency) {
2225
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.LATENCY_GAUGE, {
2226
+ val: telemetry.latency
2227
+ });
2228
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.LATENCY_HISTOGRAM_GAUGE, {
2229
+ val: telemetry.latency
2230
+ });
2231
+ update = true;
2232
+ }
2233
+ if (telemetry.childCount) {
2234
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.CHILD_COUNT, {
2235
+ val: telemetry.childCount
2236
+ });
2237
+ update = true;
2238
+ }
2239
+ if (telemetry.rx) {
2240
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.NETWORK_RX_GAUGE, {
2241
+ Inc: telemetry.rx
2242
+ });
2243
+ update = true;
2244
+ }
2245
+ if (telemetry.tx) {
2246
+ publishInstrumentController.UpdateInstrument(stsobservability.Gauge.NETWORK_TX_GAUGE, {
2247
+ Inc: telemetry.tx
2248
+ });
2249
+ update = true;
2250
+ }
2251
+ return update;
2252
+ };
2315
2253
  }
2316
2254
  const byteToHex = [];
2317
2255
  for (let i = 0; i < 256; ++i) {
@@ -2333,13 +2271,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2333
2271
  }
2334
2272
  const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2335
2273
  const native = { randomUUID };
2336
- function v4(options, buf, offset) {
2337
- var _a;
2338
- if (native.randomUUID && true && !options) {
2339
- return native.randomUUID();
2340
- }
2274
+ function _v4(options, buf, offset) {
2341
2275
  options = options || {};
2342
- const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
2276
+ const rnds = options.random ?? options.rng?.() ?? rng();
2343
2277
  if (rnds.length < 16) {
2344
2278
  throw new Error("Random bytes length must be >= 16");
2345
2279
  }
@@ -2347,6 +2281,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2347
2281
  rnds[8] = rnds[8] & 63 | 128;
2348
2282
  return unsafeStringify(rnds);
2349
2283
  }
2284
+ function v4(options, buf, offset) {
2285
+ if (native.randomUUID && true && !options) {
2286
+ return native.randomUUID();
2287
+ }
2288
+ return _v4(options);
2289
+ }
2350
2290
  var lodash_merge = { exports: {} };
2351
2291
  lodash_merge.exports;
2352
2292
  var hasRequiredLodash_merge;
@@ -2373,7 +2313,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2373
2313
  var freeModule = freeExports && true && module2 && !module2.nodeType && module2;
2374
2314
  var moduleExports = freeModule && freeModule.exports === freeExports;
2375
2315
  var freeProcess = moduleExports && freeGlobal.process;
2376
- var nodeUtil = function() {
2316
+ var nodeUtil = (function() {
2377
2317
  try {
2378
2318
  var types = freeModule && freeModule.require && freeModule.require("util").types;
2379
2319
  if (types) {
@@ -2382,7 +2322,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2382
2322
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
2383
2323
  } catch (e) {
2384
2324
  }
2385
- }();
2325
+ })();
2386
2326
  var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
2387
2327
  function apply(func, thisArg, args) {
2388
2328
  switch (args.length) {
@@ -2421,29 +2361,29 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2421
2361
  var coreJsData = root["__core-js_shared__"];
2422
2362
  var funcToString = funcProto.toString;
2423
2363
  var hasOwnProperty = objectProto.hasOwnProperty;
2424
- var maskSrcKey = function() {
2364
+ var maskSrcKey = (function() {
2425
2365
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
2426
2366
  return uid ? "Symbol(src)_1." + uid : "";
2427
- }();
2367
+ })();
2428
2368
  var nativeObjectToString = objectProto.toString;
2429
2369
  var objectCtorString = funcToString.call(Object);
2430
2370
  var reIsNative = RegExp(
2431
2371
  "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
2432
2372
  );
2433
- var Buffer2 = moduleExports ? root.Buffer : void 0, Symbol2 = root.Symbol, Uint8Array2 = root.Uint8Array;
2434
- Buffer2 ? Buffer2.allocUnsafe : void 0;
2373
+ var Buffer = moduleExports ? root.Buffer : void 0, Symbol2 = root.Symbol, Uint8Array2 = root.Uint8Array;
2374
+ Buffer ? Buffer.allocUnsafe : void 0;
2435
2375
  var getPrototype = overArg(Object.getPrototypeOf, Object), objectCreate = Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, symToStringTag = Symbol2 ? Symbol2.toStringTag : void 0;
2436
- var defineProperty = function() {
2376
+ var defineProperty = (function() {
2437
2377
  try {
2438
2378
  var func = getNative(Object, "defineProperty");
2439
2379
  func({}, "", {});
2440
2380
  return func;
2441
2381
  } catch (e) {
2442
2382
  }
2443
- }();
2444
- var nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0, nativeMax = Math.max, nativeNow = Date.now;
2383
+ })();
2384
+ var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0, nativeMax = Math.max, nativeNow = Date.now;
2445
2385
  var Map2 = getNative(root, "Map"), nativeCreate = getNative(Object, "create");
2446
- var baseCreate = /* @__PURE__ */ function() {
2386
+ var baseCreate = /* @__PURE__ */ (function() {
2447
2387
  function object() {
2448
2388
  }
2449
2389
  return function(proto) {
@@ -2458,7 +2398,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2458
2398
  object.prototype = void 0;
2459
2399
  return result;
2460
2400
  };
2461
- }();
2401
+ })();
2462
2402
  function Hash(entries) {
2463
2403
  var index = -1, length = entries == null ? 0 : entries.length;
2464
2404
  this.clear();
@@ -2965,9 +2905,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2965
2905
  function eq(value, other) {
2966
2906
  return value === other || value !== value && other !== other;
2967
2907
  }
2968
- var isArguments = baseIsArguments(/* @__PURE__ */ function() {
2908
+ var isArguments = baseIsArguments(/* @__PURE__ */ (function() {
2969
2909
  return arguments;
2970
- }()) ? baseIsArguments : function(value) {
2910
+ })()) ? baseIsArguments : function(value) {
2971
2911
  return isObjectLike(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
2972
2912
  };
2973
2913
  var isArray = Array.isArray;
@@ -3035,1181 +2975,1124 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3035
2975
  const merge = /* @__PURE__ */ getDefaultExportFromCjs(lodash_mergeExports);
3036
2976
  chalk.level = 3;
3037
2977
  class STSWorkerManager {
2978
+ //#agentSession: string = null;
2979
+ #workersEx = {};
2980
+ #options;
2981
+ #STSInstrumentController = null;
2982
+ #telemetryProcessor = null;
2983
+ #archiveList = [];
2984
+ #id;
2985
+ #messages = {};
2986
+ #archiveDeleteTimeout = 30;
3038
2987
  constructor(options) {
3039
- __privateAdd(this, _STSWorkerManager_instances);
3040
- //#agentSession: string = null;
3041
- __privateAdd(this, _workersEx, {});
3042
- __privateAdd(this, _options2);
3043
- __privateAdd(this, _STSInstrumentController, null);
3044
- __privateAdd(this, _telemetryProcessor, null);
3045
- __privateAdd(this, _archiveList, []);
3046
- __privateAdd(this, _id);
3047
- __privateAdd(this, _messages, {});
3048
- __privateAdd(this, _archiveDeleteTimeout2, 30);
3049
- __privateAdd(this, _logMessage2, (fn, message) => {
3050
- fn(`pid: [${process.pid}] STSWorkerManager: ID: [${__privateGet(this, _id)}] Log: [${message}]`);
3051
- });
3052
- __privateAdd(this, _silly2, (message) => {
3053
- if (__privateGet(this, _options2) && __privateGet(this, _options2).logLevel >= 5) {
3054
- __privateGet(this, _logMessage2).call(this, __privateGet(this, _options2).logger.silly, message);
3055
- }
3056
- });
3057
- __privateAdd(this, _debug2, (message) => {
3058
- if (__privateGet(this, _options2) && __privateGet(this, _options2).logLevel >= 4) {
3059
- __privateGet(this, _logMessage2).call(this, __privateGet(this, _options2).logger.debug, message);
3060
- }
3061
- });
3062
- __privateAdd(this, _info2, (message) => {
3063
- if (__privateGet(this, _options2) && __privateGet(this, _options2).logLevel >= 3) {
3064
- __privateGet(this, _logMessage2).call(this, __privateGet(this, _options2).logger.info, message);
3065
- }
3066
- });
3067
- __privateAdd(this, _warn2, (message) => {
3068
- if (__privateGet(this, _options2) && __privateGet(this, _options2).logLevel >= 2) {
3069
- __privateGet(this, _logMessage2).call(this, __privateGet(this, _options2).logger.warn, message);
2988
+ this.#id = v4();
2989
+ if (options) {
2990
+ this.#options = options;
2991
+ } else {
2992
+ this.#options = {};
2993
+ }
2994
+ if (this.#options.publishInstrumentController) {
2995
+ this.#STSInstrumentController = this.#options.publishInstrumentController;
2996
+ this.#telemetryProcessor = new TelemetryProcessor();
2997
+ }
2998
+ this.#processLoopExecutor();
2999
+ }
3000
+ #logMessage = (fn, message) => {
3001
+ fn(`pid: [${process.pid}] STSWorkerManager: ID: [${this.#id}] Log: [${message}]`);
3002
+ };
3003
+ #silly = (message) => {
3004
+ if (this.#options && this.#options.logLevel >= 5) {
3005
+ this.#logMessage(this.#options.logger.silly, message);
3006
+ }
3007
+ };
3008
+ #debug = (message) => {
3009
+ if (this.#options && this.#options.logLevel >= 4) {
3010
+ this.#logMessage(this.#options.logger.debug, message);
3011
+ }
3012
+ };
3013
+ #info = (message) => {
3014
+ if (this.#options && this.#options.logLevel >= 3) {
3015
+ this.#logMessage(this.#options.logger.info, message);
3016
+ }
3017
+ };
3018
+ #warn = (message) => {
3019
+ if (this.#options && this.#options.logLevel >= 2) {
3020
+ this.#logMessage(this.#options.logger.warn, message);
3021
+ }
3022
+ };
3023
+ #error = (error) => {
3024
+ if (this.#options && this.#options.logLevel >= 1) {
3025
+ this.#logMessage(this.#options.logger.error, error);
3026
+ }
3027
+ };
3028
+ CreateRunnerCopyNoHistory(runnerEx) {
3029
+ try {
3030
+ return {
3031
+ id: runnerEx.id,
3032
+ asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
3033
+ instrumentData: { ...runnerEx.instrumentData },
3034
+ iteration: runnerEx.iteration,
3035
+ options: { ...runnerEx.options },
3036
+ state: runnerEx.state,
3037
+ workerId: runnerEx.workerId,
3038
+ workerManagerId: this.#id
3039
+ };
3040
+ } catch (error) {
3041
+ this.#error(`CreateRunnerCopyNoHistory(): Error: [${error}]`);
3042
+ throw error;
3043
+ }
3044
+ }
3045
+ CreateRunnerCopy(runnerEx) {
3046
+ try {
3047
+ const retVal = this.CreateRunnerCopyNoHistory(runnerEx);
3048
+ if (runnerEx.runnerHistory) {
3049
+ retVal.runnerHistory = [...runnerEx.runnerHistory];
3070
3050
  }
3071
- });
3072
- __privateAdd(this, _error2, (error) => {
3073
- if (__privateGet(this, _options2) && __privateGet(this, _options2).logLevel >= 1) {
3074
- __privateGet(this, _logMessage2).call(this, __privateGet(this, _options2).logger.error, error);
3051
+ return retVal;
3052
+ } catch (error) {
3053
+ this.#error(`CreateRunnerCopy(): Error: [${error}]`);
3054
+ throw error;
3055
+ }
3056
+ }
3057
+ CreateRunnerCopySmall(runnerEx) {
3058
+ try {
3059
+ const retVal = {
3060
+ id: runnerEx.id,
3061
+ iteration: runnerEx.iteration,
3062
+ state: runnerEx.state
3063
+ };
3064
+ if (runnerEx.options && runnerEx.options.runnerPlan) {
3065
+ retVal.options = {
3066
+ runnerPlan: { ...runnerEx.options.runnerPlan }
3067
+ };
3075
3068
  }
3076
- });
3077
- __privateAdd(this, _processLoopExecutor2, async () => {
3078
- try {
3079
- const removeList = [];
3080
- for (const [, workerEx] of Object.entries(__privateGet(this, _workersEx))) {
3081
- for (const [, runnerEx] of Object.entries(workerEx.runnersEx)) {
3082
- const runnerState = runnerEx.state;
3083
- if (runnerEx.archived === false && (runnerState === IRunnerState.completed || runnerState === IRunnerState.error || runnerState === IRunnerState.stopped || runnerState === IRunnerState.terminated)) {
3084
- removeList.push({
3085
- workerId: workerEx.id,
3086
- runnerId: runnerEx.id
3087
- });
3088
- }
3089
- }
3090
- }
3091
- if (removeList.length > 0) {
3092
- setTimeout(async () => {
3093
- __privateGet(this, _debug2).call(this, chalk.grey(`STSWorkerManager:#processLoopExecutor(): Removing runners from collection: [${JSON.stringify(removeList)}]`));
3094
- for (let i = 0; i < removeList.length; i++) {
3095
- const workerEx = __privateGet(this, _workersEx)[removeList[i].workerId];
3096
- if (workerEx) {
3097
- const runnerEx = workerEx.runnersEx[removeList[i].runnerId];
3098
- if (runnerEx) {
3099
- if (runnerEx.publishInstrumentController) {
3100
- __privateGet(this, _debug2).call(this, chalk.grey(`Ending publish for runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3101
- runnerEx.publishInstrumentController.EndPublish();
3069
+ return retVal;
3070
+ } catch (error) {
3071
+ this.#error(`CreateRunnerCopy(): Error: [${error}]`);
3072
+ throw error;
3073
+ }
3074
+ }
3075
+ CreateWorkerCopy(workerEx) {
3076
+ try {
3077
+ const { id, options, runnersEx, workerManagerId } = workerEx;
3078
+ const workerCopy = {
3079
+ id,
3080
+ options: { ...options },
3081
+ runners: {},
3082
+ workerManagerId
3083
+ };
3084
+ for (const [, runnerEx] of Object.entries(runnersEx)) {
3085
+ workerCopy.runners[runnerEx.id] = this.CreateRunnerCopy(runnerEx);
3086
+ }
3087
+ return workerCopy;
3088
+ } catch (error) {
3089
+ this.#error(`#CreateWorkerCopy(): Error: [${error}]`);
3090
+ throw error;
3091
+ }
3092
+ }
3093
+ CreateWorkerCopySmall(workerEx, states) {
3094
+ try {
3095
+ const workerCopy = {
3096
+ id: workerEx.id,
3097
+ runners: {}
3098
+ };
3099
+ Object.values(workerEx.runnersEx).filter((runnerEx) => states.length === 0 ? true : states.includes(runnerEx.state)).forEach((runnerEx) => {
3100
+ workerCopy.runners[runnerEx.id] = this.CreateRunnerCopySmall(runnerEx);
3101
+ });
3102
+ return workerCopy;
3103
+ } catch (error) {
3104
+ this.#error(`CreateWorkerCopySmall(): Error: [${error}]`);
3105
+ throw error;
3106
+ }
3107
+ }
3108
+ #processLoopExecutor = async () => {
3109
+ try {
3110
+ const removeList = [];
3111
+ for (const [, workerEx] of Object.entries(this.#workersEx)) {
3112
+ for (const [, runnerEx] of Object.entries(workerEx.runnersEx)) {
3113
+ const runnerState = runnerEx.state;
3114
+ if (runnerEx.archived === false && (runnerState === IRunnerState.completed || runnerState === IRunnerState.error || runnerState === IRunnerState.stopped || runnerState === IRunnerState.terminated)) {
3115
+ removeList.push({
3116
+ workerId: workerEx.id,
3117
+ runnerId: runnerEx.id
3118
+ });
3119
+ }
3120
+ }
3121
+ }
3122
+ if (removeList.length > 0) {
3123
+ setTimeout(async () => {
3124
+ this.#debug(chalk.grey(`STSWorkerManager:#processLoopExecutor(): Removing runners from collection: [${JSON.stringify(removeList)}]`));
3125
+ for (let i = 0; i < removeList.length; i++) {
3126
+ const workerEx = this.#workersEx[removeList[i].workerId];
3127
+ if (workerEx) {
3128
+ const runnerEx = workerEx.runnersEx[removeList[i].runnerId];
3129
+ if (runnerEx) {
3130
+ if (runnerEx.publishInstrumentController) {
3131
+ this.#debug(chalk.grey(`Ending publish for runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3132
+ runnerEx.publishInstrumentController.EndPublish();
3133
+ }
3134
+ if (runnerEx.state !== IRunnerState.terminated) {
3135
+ this.#debug(chalk.grey(`Archive runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3136
+ const runner = this.CreateRunnerCopy(runnerEx);
3137
+ this.#archiveList.push(runner);
3138
+ if (this.#archiveList.length > this.#options.maxArchiveListLength) {
3139
+ this.#archiveList.shift();
3102
3140
  }
3103
- if (runnerEx.state !== IRunnerState.terminated) {
3104
- __privateGet(this, _debug2).call(this, chalk.grey(`Archive runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3105
- const runner = this.CreateRunnerCopy(runnerEx);
3106
- __privateGet(this, _archiveList).push(runner);
3107
- if (__privateGet(this, _archiveList).length > __privateGet(this, _options2).maxArchiveListLength) {
3108
- __privateGet(this, _archiveList).shift();
3109
- }
3141
+ } else {
3142
+ this.#debug(chalk.grey(`Runner has been terminated and will not be archived, runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3143
+ }
3144
+ runnerEx.archived = true;
3145
+ if (this.#archiveDeleteTimeout !== 0) {
3146
+ if (isNode) {
3147
+ setTimeout(() => delete workerEx.runnersEx[removeList[i].runnerId], this.#archiveDeleteTimeout * 1e3).unref();
3110
3148
  } else {
3111
- __privateGet(this, _debug2).call(this, chalk.grey(`Runner has been terminated and will not be archived, runner: [${JSON.stringify(runnerEx.asyncRunnerContext)}]`));
3112
- }
3113
- runnerEx.archived = true;
3114
- if (__privateGet(this, _archiveDeleteTimeout2) !== 0) {
3115
- if (isNode) {
3116
- setTimeout(() => delete workerEx.runnersEx[removeList[i].runnerId], __privateGet(this, _archiveDeleteTimeout2) * 1e3).unref();
3117
- } else {
3118
- setTimeout(() => delete workerEx.runnersEx[removeList[i].runnerId], __privateGet(this, _archiveDeleteTimeout2) * 1e3);
3119
- }
3149
+ setTimeout(() => delete workerEx.runnersEx[removeList[i].runnerId], this.#archiveDeleteTimeout * 1e3);
3120
3150
  }
3121
3151
  }
3122
3152
  }
3123
3153
  }
3124
- for (const [, workerEx] of Object.entries(__privateGet(this, _workersEx))) {
3125
- __privateGet(this, _debug2).call(this, chalk.grey(`STSWorkerManager:#processLoopExecutor(): Remaining runners from worker: [${workerEx.id}]: [${Object.keys(workerEx.runnersEx).length}]`));
3126
- }
3127
- setTimeout(__privateGet(this, _processLoopExecutor2), 1e3);
3128
- }, 100);
3129
- } else {
3130
- setTimeout(__privateGet(this, _processLoopExecutor2), 1e3);
3131
- }
3132
- } catch (error) {
3133
- __privateGet(this, _error2).call(this, `processLoopExecutor(): Error: [${error}]`);
3134
- throw error;
3135
- }
3136
- });
3137
- __publicField(this, "GetWorkers", async () => {
3138
- __privateGet(this, _debug2).call(this, `GetWorkers()`);
3139
- try {
3140
- await __privateGet(this, _SyncWorkerDataFromWorkers).call(this);
3141
- const retVal = {};
3142
- for (const [, workerEx] of Object.entries(__privateGet(this, _workersEx))) {
3143
- retVal[workerEx.id] = this.CreateWorkerCopy(workerEx);
3144
- }
3145
- return retVal;
3146
- } catch (error) {
3147
- __privateGet(this, _error2).call(this, `GetWorkers(): Error: [${error}]`);
3148
- throw error;
3149
- }
3150
- });
3151
- // only include runners that are in the specified states.
3152
- // Use [] to include all runners irrespective of state.
3153
- __publicField(this, "GetWorkersSmall", async (states) => {
3154
- __privateGet(this, _debug2).call(this, `GetWorkersSmall()`);
3155
- try {
3156
- await __privateGet(this, _SyncWorkerDataFromWorkers).call(this);
3157
- const retVal = {};
3158
- for (const [, workerEx] of Object.entries(__privateGet(this, _workersEx))) {
3159
- retVal[workerEx.id] = this.CreateWorkerCopySmall(workerEx, states);
3160
- }
3161
- return retVal;
3162
- } catch (error) {
3163
- __privateGet(this, _error2).call(this, `GetWorkers(): Error: [${error}]`);
3164
- throw error;
3165
- }
3166
- });
3167
- // Filter by plan and/or tag. Leave blank to not use in filter.
3168
- __publicField(this, "GetArchiveList", async (runnerSearchFilters) => {
3169
- __privateGet(this, _debug2).call(this, `GetArchiveList()`);
3170
- try {
3171
- return __privateGet(this, _archiveList).filter((runner) => {
3172
- var _a, _b;
3173
- return !runnerSearchFilters.plan ? true : ((_b = (_a = runner.options.runnerPlan) == null ? void 0 : _a.plan) == null ? void 0 : _b.localeCompare(runnerSearchFilters.plan)) === 0;
3174
- }).filter((runner) => {
3175
- var _a, _b;
3176
- return !runnerSearchFilters.planInstanceId ? true : ((_b = (_a = runner.options.runnerPlan) == null ? void 0 : _a.planInstanceId) == null ? void 0 : _b.localeCompare(runnerSearchFilters.planInstanceId)) === 0;
3177
- }).filter((runner) => {
3178
- var _a;
3179
- return !runnerSearchFilters.tag ? true : (_a = runner.options.tag) == null ? void 0 : _a.includes(runnerSearchFilters.tag);
3180
- }).filter((runner) => !runnerSearchFilters.userDataKey ? true : !runner.options.userData ? false : !!runner.options.userData[runnerSearchFilters.userDataKey]);
3181
- } catch (error) {
3182
- __privateGet(this, _error2).call(this, `GetArchiveList(): Error: [${error}]`);
3183
- return [];
3154
+ }
3155
+ for (const [, workerEx] of Object.entries(this.#workersEx)) {
3156
+ this.#debug(chalk.grey(`STSWorkerManager:#processLoopExecutor(): Remaining runners from worker: [${workerEx.id}]: [${Object.keys(workerEx.runnersEx).length}]`));
3157
+ }
3158
+ setTimeout(this.#processLoopExecutor, 1e3);
3159
+ }, 100);
3160
+ } else {
3161
+ setTimeout(this.#processLoopExecutor, 1e3);
3184
3162
  }
3185
- });
3186
- __publicField(this, "GetWorker", async (workerId) => {
3187
- __privateGet(this, _debug2).call(this, `GetWorker()`);
3188
- try {
3189
- await __privateGet(this, _SyncWorkerDataFromWorker).call(this, __privateGet(this, _workersEx)[workerId]);
3190
- return this.CreateWorkerCopy(__privateGet(this, _workersEx)[workerId]);
3191
- } catch (error) {
3192
- __privateGet(this, _error2).call(this, `GetWorker(): Error: [${error}]`);
3193
- throw error;
3163
+ } catch (error) {
3164
+ this.#error(`processLoopExecutor(): Error: [${error}]`);
3165
+ throw error;
3166
+ }
3167
+ };
3168
+ get id() {
3169
+ return this.#id;
3170
+ }
3171
+ GetWorkers = async () => {
3172
+ this.#debug(`GetWorkers()`);
3173
+ try {
3174
+ await this.#SyncWorkerDataFromWorkers();
3175
+ const retVal = {};
3176
+ for (const [, workerEx] of Object.entries(this.#workersEx)) {
3177
+ retVal[workerEx.id] = this.CreateWorkerCopy(workerEx);
3194
3178
  }
3195
- });
3196
- __publicField(this, "GetRunner", async (workerId, runnerId) => {
3197
- __privateGet(this, _debug2).call(this, `GetRunner()`);
3198
- try {
3199
- await __privateGet(this, _SyncWorkerDataFromWorker).call(this, __privateGet(this, _workersEx)[workerId]);
3200
- return this.CreateRunnerCopy(__privateGet(this, _workersEx)[workerId].runnersEx[runnerId]);
3201
- } catch (error) {
3202
- __privateGet(this, _error2).call(this, `GetRunner(): Error: [${error}]`);
3203
- throw error;
3179
+ return retVal;
3180
+ } catch (error) {
3181
+ this.#error(`GetWorkers(): Error: [${error}]`);
3182
+ throw error;
3183
+ }
3184
+ };
3185
+ // only include runners that are in the specified states.
3186
+ // Use [] to include all runners irrespective of state.
3187
+ GetWorkersSmall = async (states) => {
3188
+ this.#debug(`GetWorkersSmall()`);
3189
+ try {
3190
+ await this.#SyncWorkerDataFromWorkers();
3191
+ const retVal = {};
3192
+ for (const [, workerEx] of Object.entries(this.#workersEx)) {
3193
+ retVal[workerEx.id] = this.CreateWorkerCopySmall(workerEx, states);
3204
3194
  }
3205
- });
3206
- __publicField(this, "AddWorker", async (workerOptions, useWorkerFactory) => {
3207
- __privateGet(this, _debug2).call(this, `AddWorker()`);
3208
- try {
3209
- let workerFactory;
3210
- if (useWorkerFactory) {
3211
- workerFactory = useWorkerFactory;
3212
- } else {
3213
- workerFactory = __privateGet(this, _options2).workerFactory;
3214
- }
3215
- const {
3216
- port1,
3217
- // process message port
3218
- port2
3219
- // collector message port
3220
- } = new MessageChannel();
3221
- if (!isNode) {
3222
- port1.start();
3223
- }
3224
- const workerId = v4();
3225
- const stsWorkerEx = {
3226
- id: workerId,
3227
- workerManagerId: __privateGet(this, _id),
3228
- worker: workerFactory.createWorkerThreadWorker(),
3229
- workerEvents: [],
3230
- messagePort: port1,
3231
- options: workerOptions,
3232
- runnersEx: {},
3233
- runnersEvents: {},
3234
- GetRunner: (id) => __privateGet(this, _workersEx)[workerId].runnersEx[id],
3235
- // Commands to execute on individual runners
3236
- AddRunner: (runnerOptions) => this.AddRunnerToWorker(stsWorkerEx, runnerOptions),
3237
- StartRunner: (runner) => __privateGet(this, _StartRunner2).call(this, stsWorkerEx, runner),
3238
- StopRunner: (runner) => __privateGet(this, _StopRunner2).call(this, stsWorkerEx, runner),
3239
- PauseRunner: (runner) => __privateGet(this, _PauseRunner2).call(this, stsWorkerEx, runner),
3240
- ResumeRunner: (runner) => __privateGet(this, _ResumeRunner2).call(this, stsWorkerEx, runner),
3241
- TerminateRunner: (runner) => __privateGet(this, _TerminateRunner2).call(this, stsWorkerEx, runner),
3242
- ResetRunner: (runner) => __privateGet(this, _ResetRunner2).call(this, stsWorkerEx, runner),
3243
- ExecuteRunner: (runner) => __privateGet(this, _ExecuteRunner2).call(this, stsWorkerEx, runner),
3244
- UpdateRunner: (runner, runnerOptions) => __privateGet(this, _UpdateRunner2).call(this, stsWorkerEx, runner, runnerOptions),
3245
- // Commands to execute on all runners
3246
- Start: () => __privateGet(this, _StartWorker).call(this, stsWorkerEx),
3247
- Stop: () => __privateGet(this, _StopWorker).call(this, stsWorkerEx),
3248
- Pause: () => __privateGet(this, _PauseWorker).call(this, stsWorkerEx),
3249
- Resume: () => __privateGet(this, _ResumeWorker).call(this, stsWorkerEx),
3250
- Terminate: () => __privateGet(this, _TerminateWorker).call(this, stsWorkerEx),
3251
- Reset: () => __privateGet(this, _ResetWorker).call(this, stsWorkerEx),
3252
- Execute: () => __privateGet(this, _ExecuteWorker).call(this, stsWorkerEx),
3253
- Update: (runnerOptions) => __privateGet(this, _UpdateOptionsWorker).call(this, stsWorkerEx, runnerOptions),
3254
- on: (eventName, cb) => {
3255
- stsWorkerEx.workerEvents.push({
3256
- eventName,
3257
- cb
3258
- });
3259
- return stsWorkerEx;
3260
- }
3261
- };
3262
- if (__privateGet(this, _STSInstrumentController)) {
3263
- __privateGet(this, _STSInstrumentController).LogEx(chalk.yellow(`pid: [${process.pid}] Creating new worker: [${stsWorkerEx.id}]`));
3264
- }
3265
- __privateGet(this, _debug2).call(this, `AddWorker::workerThreadWorkerOptions: Worker ID: [${stsWorkerEx.id}] Options: [${stsWorkerEx.options}]`);
3266
- if (stsWorkerEx.options.mocked) {
3267
- stsWorkerEx.worker.SetPort({
3268
- command: eIWMessageCommands.MessagePort,
3269
- payload: {
3270
- messageId: v4(),
3271
- port: port2,
3272
- options: {
3273
- ...stsWorkerEx.options
3274
- },
3275
- workerId
3276
- }
3195
+ return retVal;
3196
+ } catch (error) {
3197
+ this.#error(`GetWorkers(): Error: [${error}]`);
3198
+ throw error;
3199
+ }
3200
+ };
3201
+ get WorkersEx() {
3202
+ return this.#workersEx;
3203
+ }
3204
+ // Filter by plan and/or tag. Leave blank to not use in filter.
3205
+ GetArchiveList = async (runnerSearchFilters) => {
3206
+ this.#debug(`GetArchiveList()`);
3207
+ try {
3208
+ return this.#archiveList.filter((runner) => !runnerSearchFilters.plan ? true : runner.options.runnerPlan?.plan?.localeCompare(runnerSearchFilters.plan) === 0).filter((runner) => !runnerSearchFilters.planInstanceId ? true : runner.options.runnerPlan?.planInstanceId?.localeCompare(runnerSearchFilters.planInstanceId) === 0).filter((runner) => !runnerSearchFilters.tag ? true : runner.options.tag?.includes(runnerSearchFilters.tag)).filter((runner) => !runnerSearchFilters.userDataKey ? true : !runner.options.userData ? false : !!runner.options.userData[runnerSearchFilters.userDataKey]);
3209
+ } catch (error) {
3210
+ this.#error(`GetArchiveList(): Error: [${error}]`);
3211
+ return [];
3212
+ }
3213
+ };
3214
+ GetWorker = async (workerId) => {
3215
+ this.#debug(`GetWorker()`);
3216
+ try {
3217
+ await this.#SyncWorkerDataFromWorker(this.#workersEx[workerId]);
3218
+ return this.CreateWorkerCopy(this.#workersEx[workerId]);
3219
+ } catch (error) {
3220
+ this.#error(`GetWorker(): Error: [${error}]`);
3221
+ throw error;
3222
+ }
3223
+ };
3224
+ GetRunner = async (workerId, runnerId) => {
3225
+ this.#debug(`GetRunner()`);
3226
+ try {
3227
+ await this.#SyncWorkerDataFromWorker(this.#workersEx[workerId]);
3228
+ return this.CreateRunnerCopy(this.#workersEx[workerId].runnersEx[runnerId]);
3229
+ } catch (error) {
3230
+ this.#error(`GetRunner(): Error: [${error}]`);
3231
+ throw error;
3232
+ }
3233
+ };
3234
+ AddWorker = async (workerOptions, useWorkerFactory) => {
3235
+ this.#debug(`AddWorker()`);
3236
+ try {
3237
+ let workerFactory;
3238
+ if (useWorkerFactory) {
3239
+ workerFactory = useWorkerFactory;
3240
+ } else {
3241
+ workerFactory = this.#options.workerFactory;
3242
+ }
3243
+ const {
3244
+ port1,
3245
+ // process message port
3246
+ port2
3247
+ // collector message port
3248
+ } = new MessageChannel();
3249
+ if (!isNode) {
3250
+ port1.start();
3251
+ }
3252
+ const workerId = v4();
3253
+ const stsWorkerEx = {
3254
+ id: workerId,
3255
+ workerManagerId: this.#id,
3256
+ worker: workerFactory.createWorkerThreadWorker(),
3257
+ workerEvents: [],
3258
+ messagePort: port1,
3259
+ options: workerOptions,
3260
+ runnersEx: {},
3261
+ runnersEvents: {},
3262
+ GetRunner: (id) => this.#workersEx[workerId].runnersEx[id],
3263
+ // Commands to execute on individual runners
3264
+ AddRunner: (runnerOptions) => this.AddRunnerToWorker(stsWorkerEx, runnerOptions),
3265
+ StartRunner: (runner) => this.#StartRunner(stsWorkerEx, runner),
3266
+ StopRunner: (runner) => this.#StopRunner(stsWorkerEx, runner),
3267
+ PauseRunner: (runner) => this.#PauseRunner(stsWorkerEx, runner),
3268
+ ResumeRunner: (runner) => this.#ResumeRunner(stsWorkerEx, runner),
3269
+ TerminateRunner: (runner) => this.#TerminateRunner(stsWorkerEx, runner),
3270
+ ResetRunner: (runner) => this.#ResetRunner(stsWorkerEx, runner),
3271
+ ExecuteRunner: (runner) => this.#ExecuteRunner(stsWorkerEx, runner),
3272
+ UpdateRunner: (runner, runnerOptions) => this.#UpdateRunner(stsWorkerEx, runner, runnerOptions),
3273
+ // Commands to execute on all runners
3274
+ Start: () => this.#StartWorker(stsWorkerEx),
3275
+ Stop: () => this.#StopWorker(stsWorkerEx),
3276
+ Pause: () => this.#PauseWorker(stsWorkerEx),
3277
+ Resume: () => this.#ResumeWorker(stsWorkerEx),
3278
+ Terminate: () => this.#TerminateWorker(stsWorkerEx),
3279
+ Reset: () => this.#ResetWorker(stsWorkerEx),
3280
+ Execute: () => this.#ExecuteWorker(stsWorkerEx),
3281
+ Update: (runnerOptions) => this.#UpdateOptionsWorker(stsWorkerEx, runnerOptions),
3282
+ on: (eventName, cb) => {
3283
+ stsWorkerEx.workerEvents.push({
3284
+ eventName,
3285
+ cb
3277
3286
  });
3278
- } else {
3279
- __privateGet(this, _PostMessageToWorkerUsingDefaultChannel).call(this, stsWorkerEx, eIWMessageCommands.MessagePort, {
3287
+ return stsWorkerEx;
3288
+ }
3289
+ };
3290
+ if (this.#STSInstrumentController) {
3291
+ this.#STSInstrumentController.LogEx(chalk.yellow(`pid: [${process.pid}] Creating new worker: [${stsWorkerEx.id}]`));
3292
+ }
3293
+ this.#debug(`AddWorker::workerThreadWorkerOptions: Worker ID: [${stsWorkerEx.id}] Options: [${stsWorkerEx.options}]`);
3294
+ if (stsWorkerEx.options.mocked) {
3295
+ stsWorkerEx.worker.SetPort({
3296
+ command: eIWMessageCommands.MessagePort,
3297
+ payload: {
3280
3298
  messageId: v4(),
3281
3299
  port: port2,
3282
- //applicationStoreState: stateCopy,
3283
3300
  options: {
3284
3301
  ...stsWorkerEx.options
3285
3302
  },
3286
3303
  workerId
3287
- }, port2);
3288
- }
3289
- if (!stsWorkerEx.options.mocked) {
3290
- if (isNode) {
3291
- stsWorkerEx.worker.on("exit", (code) => {
3292
- try {
3293
- __privateGet(this, _debug2).call(this, chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker exited with code: ${code}`));
3294
- __privateGet(this, _EmitWorkerEvent).call(this, "exit", stsWorkerEx);
3295
- if (__privateGet(this, _workersEx)[stsWorkerEx.id]) {
3296
- delete __privateGet(this, _workersEx)[stsWorkerEx.id];
3297
- __privateGet(this, _debug2).call(this, chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker: [${stsWorkerEx.id}] has been removed from the worker collection.`));
3298
- }
3299
- } catch (error) {
3300
- __privateGet(this, _error2).call(this, chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(exit): Error: [${error}] Worker: [${stsWorkerEx.id}]`));
3301
- }
3302
- });
3303
- stsWorkerEx.worker.on("error", (error) => {
3304
- try {
3305
- __privateGet(this, _error2).call(this, chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(error): Worker error: ${error}`));
3306
- __privateGet(this, _EmitWorkerEvent).call(this, "error", stsWorkerEx);
3307
- } catch (error2) {
3308
- __privateGet(this, _error2).call(this, chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3309
- }
3310
- });
3311
- } else {
3312
- stsWorkerEx.worker.onerror = (error) => {
3313
- try {
3314
- __privateGet(this, _error2).call(this, chalk.red("STSWorkerManager:stsWorkerEx.worker.onerror(): Error in worker:", error));
3315
- __privateGet(this, _EmitWorkerEvent).call(this, "onerror", stsWorkerEx);
3316
- if (__privateGet(this, _workersEx)[stsWorkerEx.id]) {
3317
- delete __privateGet(this, _workersEx)[stsWorkerEx.id];
3318
- __privateGet(this, _debug2).call(this, chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.onerror(error): Worker: [${stsWorkerEx.id}] has been removed from the worker collection.`));
3319
- }
3320
- } catch (error2) {
3321
- __privateGet(this, _error2).call(this, chalk.red(`STSWorkerManager:stsWorkerEx.worker.onerror(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3322
- }
3323
- };
3324
- stsWorkerEx.worker.onmessageerror = (error) => {
3325
- try {
3326
- __privateGet(this, _error2).call(this, chalk.red("STSWorkerManager:stsWorkerEx.worker.onmessageerror(): Message error in worker:", error));
3327
- __privateGet(this, _EmitWorkerEvent).call(this, "onmessageerror", stsWorkerEx);
3328
- } catch (error2) {
3329
- __privateGet(this, _error2).call(this, chalk.red(`STSWorkerManager:stsWorkerEx.worker.onmessageerror(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3330
- }
3331
- };
3332
- }
3333
- }
3334
- const processMessage = (data) => {
3335
- try {
3336
- const publishMessagePayload2 = data;
3337
- switch (publishMessagePayload2.command) {
3338
- case eIWMessageCommands.MessagePortResponse:
3339
- __privateGet(this, _debug2).call(this, `AddWorker:processMessage(): eIWMessageCommands.MessagePortResponse`);
3340
- break;
3341
- case eIWMessageCommands.InstrumentTelemetry:
3342
- __privateGet(this, _ProcessTelemetry).call(this, stsWorkerEx, publishMessagePayload2.payload);
3343
- break;
3344
- case eIWMessageCommands.RunnerStateChange:
3345
- __privateGet(this, _RunnerStateChange).call(this, stsWorkerEx, publishMessagePayload2.payload);
3346
- break;
3347
- case eIWMessageCommands.GetRunnersResponse:
3348
- __privateMethod(this, _STSWorkerManager_instances, GetRunnersResponse_fn).call(this, stsWorkerEx, publishMessagePayload2.payload);
3349
- break;
3350
- case eIWMessageCommands.AddRunnerResponse:
3351
- case eIWMessageCommands.StartRunnerResponse:
3352
- case eIWMessageCommands.StopRunnerResponse:
3353
- case eIWMessageCommands.PauseRunnerResponse:
3354
- case eIWMessageCommands.ResumeRunnerResponse:
3355
- case eIWMessageCommands.ExecuteRunnerResponse:
3356
- case eIWMessageCommands.ResetRunnerResponse:
3357
- case eIWMessageCommands.UpdateRunnerResponse:
3358
- case eIWMessageCommands.TerminateRunnerResponse:
3359
- __privateMethod(this, _STSWorkerManager_instances, ProcessRunnerResponse_fn).call(this, stsWorkerEx, publishMessagePayload2.payload);
3360
- break;
3361
- default:
3362
- __privateGet(this, _warn2).call(this, `processMessage::default: Command Not Found: [${publishMessagePayload2.command}]`);
3363
- }
3364
- } catch (error) {
3365
- __privateGet(this, _error2).call(this, `AddWorker:processMessage(): Error: [${error}]`);
3366
- throw error;
3367
3304
  }
3368
- };
3369
- let publishMessagePayload;
3305
+ });
3306
+ } else {
3307
+ this.#PostMessageToWorkerUsingDefaultChannel(stsWorkerEx, eIWMessageCommands.MessagePort, {
3308
+ messageId: v4(),
3309
+ port: port2,
3310
+ //applicationStoreState: stateCopy,
3311
+ options: {
3312
+ ...stsWorkerEx.options
3313
+ },
3314
+ workerId
3315
+ }, port2);
3316
+ }
3317
+ if (!stsWorkerEx.options.mocked) {
3370
3318
  if (isNode) {
3371
- stsWorkerEx.messagePort.on("message", (data) => {
3372
- publishMessagePayload = data;
3373
- processMessage(publishMessagePayload);
3319
+ stsWorkerEx.worker.on("exit", (code) => {
3320
+ try {
3321
+ this.#debug(chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker exited with code: ${code}`));
3322
+ this.#EmitWorkerEvent("exit", stsWorkerEx);
3323
+ if (this.#workersEx[stsWorkerEx.id]) {
3324
+ delete this.#workersEx[stsWorkerEx.id];
3325
+ this.#debug(chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker: [${stsWorkerEx.id}] has been removed from the worker collection.`));
3326
+ }
3327
+ } catch (error) {
3328
+ this.#error(chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(exit): Error: [${error}] Worker: [${stsWorkerEx.id}]`));
3329
+ }
3374
3330
  });
3375
- } else {
3376
- stsWorkerEx.messagePort.addEventListener("message", (data) => {
3377
- publishMessagePayload = data.data;
3378
- processMessage(publishMessagePayload);
3331
+ stsWorkerEx.worker.on("error", (error) => {
3332
+ try {
3333
+ this.#error(chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(error): Worker error: ${error}`));
3334
+ this.#EmitWorkerEvent("error", stsWorkerEx);
3335
+ } catch (error2) {
3336
+ this.#error(chalk.red(`STSWorkerManager:stsWorkerEx.worker.on(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3337
+ }
3379
3338
  });
3380
- }
3381
- __privateGet(this, _workersEx)[stsWorkerEx.id] = stsWorkerEx;
3382
- __privateGet(this, _debug2).call(this, `Added worker: [${stsWorkerEx.id}]`);
3383
- await stsutils.Sleep(10);
3384
- const worker = await this.GetWorker(stsWorkerEx.id);
3385
- if (worker.id.localeCompare(stsWorkerEx.id) === 0) {
3386
- return stsWorkerEx;
3387
3339
  } else {
3388
- throw new Error("AddWorker(): Could not get newly created worker.");
3389
- }
3390
- } catch (error) {
3391
- __privateGet(this, _error2).call(this, `AddWorker: Error: [${error}]`);
3392
- throw error;
3393
- }
3394
- });
3395
- __publicField(this, "AddRunnerToWorker", async (stsWorkerEx, runnerOptions) => {
3396
- __privateGet(this, _debug2).call(this, `AddRunnerToWorker()`);
3397
- try {
3398
- const runnerEx = __privateGet(this, _CreateAsyncRunner).call(this, stsWorkerEx, runnerOptions);
3399
- stsWorkerEx.runnersEx[runnerEx.id] = runnerEx;
3400
- const retVal = await __privateGet(this, _SetRunnerIntoWorker).call(this, stsWorkerEx, runnerEx);
3401
- if (runnerEx.publishInstrumentController) {
3402
- runnerEx.publishInstrumentController.LogEx(chalk.green(`Added runner: [${runnerEx.id}] into worker: [${stsWorkerEx.id}]`));
3403
- }
3404
- if (retVal) {
3405
- __privateGet(this, _debug2).call(this, chalk.green(`Added runner: [${runnerEx.id}] into worker: [${stsWorkerEx.id}] result: [${JSON.stringify(retVal)}]`));
3340
+ stsWorkerEx.worker.onerror = (error) => {
3341
+ try {
3342
+ this.#error(chalk.red("STSWorkerManager:stsWorkerEx.worker.onerror(): Error in worker:", error));
3343
+ this.#EmitWorkerEvent("onerror", stsWorkerEx);
3344
+ if (this.#workersEx[stsWorkerEx.id]) {
3345
+ delete this.#workersEx[stsWorkerEx.id];
3346
+ this.#debug(chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.onerror(error): Worker: [${stsWorkerEx.id}] has been removed from the worker collection.`));
3347
+ }
3348
+ } catch (error2) {
3349
+ this.#error(chalk.red(`STSWorkerManager:stsWorkerEx.worker.onerror(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3350
+ }
3351
+ };
3352
+ stsWorkerEx.worker.onmessageerror = (error) => {
3353
+ try {
3354
+ this.#error(chalk.red("STSWorkerManager:stsWorkerEx.worker.onmessageerror(): Message error in worker:", error));
3355
+ this.#EmitWorkerEvent("onmessageerror", stsWorkerEx);
3356
+ } catch (error2) {
3357
+ this.#error(chalk.red(`STSWorkerManager:stsWorkerEx.worker.onmessageerror(error): Error: [${error2}] Worker: [${stsWorkerEx.id}]`));
3358
+ }
3359
+ };
3406
3360
  }
3407
- return runnerEx;
3408
- } catch (error) {
3409
- __privateGet(this, _error2).call(this, `AddRunnerToWorker(): Error: [${error}]`);
3410
- throw error;
3411
3361
  }
3412
- });
3413
- __privateAdd(this, _SetRunnerIntoWorker, async (workerEx, runnerEx) => {
3414
- return new Promise((resolve, reject) => {
3362
+ const processMessage = (data) => {
3415
3363
  try {
3416
- const command = eIWMessageCommands.AddRunner;
3417
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3418
- const payload = {
3419
- messageId,
3420
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3421
- };
3422
- workerEx.messagePort.postMessage({ command, payload });
3364
+ const publishMessagePayload2 = data;
3365
+ switch (publishMessagePayload2.command) {
3366
+ case eIWMessageCommands.MessagePortResponse:
3367
+ this.#debug(`AddWorker:processMessage(): eIWMessageCommands.MessagePortResponse`);
3368
+ break;
3369
+ case eIWMessageCommands.InstrumentTelemetry:
3370
+ this.#ProcessTelemetry(stsWorkerEx, publishMessagePayload2.payload);
3371
+ break;
3372
+ case eIWMessageCommands.RunnerStateChange:
3373
+ this.#RunnerStateChange(stsWorkerEx, publishMessagePayload2.payload);
3374
+ break;
3375
+ case eIWMessageCommands.GetRunnersResponse:
3376
+ this.#GetRunnersResponse(stsWorkerEx, publishMessagePayload2.payload);
3377
+ break;
3378
+ case eIWMessageCommands.AddRunnerResponse:
3379
+ case eIWMessageCommands.StartRunnerResponse:
3380
+ case eIWMessageCommands.StopRunnerResponse:
3381
+ case eIWMessageCommands.PauseRunnerResponse:
3382
+ case eIWMessageCommands.ResumeRunnerResponse:
3383
+ case eIWMessageCommands.ExecuteRunnerResponse:
3384
+ case eIWMessageCommands.ResetRunnerResponse:
3385
+ case eIWMessageCommands.UpdateRunnerResponse:
3386
+ case eIWMessageCommands.TerminateRunnerResponse:
3387
+ this.#ProcessRunnerResponse(stsWorkerEx, publishMessagePayload2.payload);
3388
+ break;
3389
+ default:
3390
+ this.#warn(`processMessage::default: Command Not Found: [${publishMessagePayload2.command}]`);
3391
+ }
3423
3392
  } catch (error) {
3424
- __privateGet(this, _error2).call(this, `#PauseRunner(): Error: [${error}]`);
3393
+ this.#error(`AddWorker:processMessage(): Error: [${error}]`);
3425
3394
  throw error;
3426
3395
  }
3427
- });
3428
- });
3429
- __privateAdd(this, _ProcessTelemetry, (workerEx, payloadContents) => {
3430
- try {
3431
- const { runner } = payloadContents;
3432
- if (workerEx.runnersEx[runner.id]) {
3433
- const runnerEx = workerEx.runnersEx[runner.id];
3434
- __privateGet(this, _SyncRunnerData).call(this, runnerEx, runner);
3435
- if (runnerEx.publishInstrumentController && __privateGet(this, _telemetryProcessor)) {
3436
- __privateGet(this, _telemetryProcessor).ProcessTelemetry(runnerEx.publishInstrumentController, runnerEx.instrumentData);
3437
- }
3438
- __privateGet(this, _EmitRunnerEvent).call(this, "Telemetry", workerEx, runner.id);
3439
- }
3440
- } catch (error) {
3441
- __privateGet(this, _error2).call(this, `ProcessTelemetry(): Error: [${error}]`);
3442
- throw error;
3443
- }
3444
- });
3445
- __privateAdd(this, _EmitWorkerEvent, (eventName, workerEx) => {
3446
- try {
3447
- workerEx.workerEvents.forEach((ev) => {
3448
- if (ev.eventName.localeCompare(eventName) === 0) {
3449
- ev.cb(workerEx);
3450
- }
3396
+ };
3397
+ let publishMessagePayload;
3398
+ if (isNode) {
3399
+ stsWorkerEx.messagePort.on("message", (data) => {
3400
+ publishMessagePayload = data;
3401
+ processMessage(publishMessagePayload);
3402
+ });
3403
+ } else {
3404
+ stsWorkerEx.messagePort.addEventListener("message", (data) => {
3405
+ publishMessagePayload = data.data;
3406
+ processMessage(publishMessagePayload);
3451
3407
  });
3452
- } catch (error) {
3453
- __privateGet(this, _error2).call(this, `EmitWorkerEvent(): Error: [${error}]`);
3454
- throw error;
3455
3408
  }
3456
- });
3457
- __privateAdd(this, _EmitRunnerEvent, (eventName, workerEx, runnerId) => {
3458
- try {
3459
- if (workerEx.runnersEvents[runnerId]) {
3460
- const runnersEvents = workerEx.runnersEvents[runnerId];
3461
- runnersEvents.forEach((ev) => {
3462
- if (ev.eventName.localeCompare(eventName) === 0) {
3463
- ev.cb(workerEx.runnersEx[runnerId]);
3464
- }
3465
- });
3466
- }
3467
- } catch (error) {
3468
- __privateGet(this, _error2).call(this, `EmitRunnerEvent(): Error: [${error}]`);
3469
- throw error;
3409
+ this.#workersEx[stsWorkerEx.id] = stsWorkerEx;
3410
+ this.#debug(`Added worker: [${stsWorkerEx.id}]`);
3411
+ await stsutils.Sleep(10);
3412
+ const worker = await this.GetWorker(stsWorkerEx.id);
3413
+ if (worker.id.localeCompare(stsWorkerEx.id) === 0) {
3414
+ return stsWorkerEx;
3415
+ } else {
3416
+ throw new Error("AddWorker(): Could not get newly created worker.");
3470
3417
  }
3471
- });
3472
- //@@ make this have an event
3473
- //@@ make refactor event to own method
3474
- //@@ check for other events to capture
3475
- __privateAdd(this, _RunnerStateChange, (workerEx, payloadContents) => {
3476
- try {
3477
- const { runner } = payloadContents;
3478
- if (workerEx.runnersEx[runner.id]) {
3479
- const runnerEx = workerEx.runnersEx[runner.id];
3480
- const previousState = runnerEx.state;
3481
- runnerEx.state = runner.state;
3482
- if (!runnerEx.runnerHistory) {
3483
- runnerEx.runnerHistory = [];
3484
- }
3485
- runnerEx.runnerHistory.push({
3486
- eventDate: /* @__PURE__ */ new Date(),
3487
- runner: { ...runner }
3488
- });
3489
- __privateGet(this, _SyncRunnerData).call(this, runnerEx, runner);
3490
- __privateGet(this, _debug2).call(this, `STSWorkerManager:#RunnerStateChange(): Worker: [${workerEx.id}] Runner: [${runner.id}] Previous State: [${previousState}] State: [${runner.state}]`);
3491
- __privateGet(this, _EmitRunnerEvent).call(this, "StateChange", workerEx, runner.id);
3492
- }
3493
- } catch (error) {
3494
- __privateGet(this, _error2).call(this, `RunnerStateChange(): Error: [${error}]`);
3495
- throw error;
3418
+ } catch (error) {
3419
+ this.#error(`AddWorker: Error: [${error}]`);
3420
+ throw error;
3421
+ }
3422
+ };
3423
+ AddRunnerToWorker = async (stsWorkerEx, runnerOptions) => {
3424
+ this.#debug(`AddRunnerToWorker()`);
3425
+ try {
3426
+ const runnerEx = this.#CreateAsyncRunner(stsWorkerEx, runnerOptions);
3427
+ stsWorkerEx.runnersEx[runnerEx.id] = runnerEx;
3428
+ const retVal = await this.#SetRunnerIntoWorker(stsWorkerEx, runnerEx);
3429
+ if (runnerEx.publishInstrumentController) {
3430
+ runnerEx.publishInstrumentController.LogEx(chalk.green(`Added runner: [${runnerEx.id}] into worker: [${stsWorkerEx.id}]`));
3431
+ }
3432
+ if (retVal) {
3433
+ this.#debug(chalk.green(`Added runner: [${runnerEx.id}] into worker: [${stsWorkerEx.id}] result: [${JSON.stringify(retVal)}]`));
3496
3434
  }
3497
- });
3498
- __privateAdd(this, _CreateAsyncRunner, (workerEx, runnerOptions) => {
3499
- const runnerId = v4();
3500
- if (__privateGet(this, _STSInstrumentController)) {
3501
- __privateGet(this, _STSInstrumentController).LogEx(chalk.yellow(`Creating new async runner: [${runnerId}]`));
3502
- }
3503
- const asyncRunnerContext = {
3504
- // [level1]@[level2]^[level3]|[level4]
3505
- // [hostName]@[agentId]-[userAgent]^[workerId]|[runnerId]
3506
- nid: `${workerEx.options.hostName}${stsutils.ModelDelimeter.COMPONENT_SEPERATOR}${workerEx.options.agentId}-${workerEx.options.userAgent}${stsutils.ModelDelimeter.NID_SEPERATOR}${workerEx.id}${stsutils.ModelDelimeter.SEPERATOR}${runnerId}`,
3507
- hostName: workerEx.options.hostName,
3508
- // level 1 (e.g. host name)
3509
- agentName: `${workerEx.options.agentId}-${workerEx.options.userAgent}`,
3510
- // level 2 (e.g. service instance ID or user agent type and tab or instance)
3511
- threadId: `${workerEx.id}`,
3512
- // level 3 (web worker)
3513
- id: runnerId
3514
- // level 4 // (async runner within a web worker)
3515
- };
3516
- const runnerEx = {
3517
- id: runnerId,
3518
- workerId: workerEx.id,
3519
- workerManagerId: __privateGet(this, _id),
3520
- state: IRunnerState.created,
3521
- iteration: 0,
3522
- publishInstrumentController: __privateGet(this, _STSInstrumentController) ? __privateGet(this, _STSInstrumentController).AddPublishInstrumentController(asyncRunnerContext) : void 0,
3523
- asyncRunnerContext,
3524
- options: runnerOptions,
3525
- runnerHistory: [],
3526
- instrumentData: {
3527
- requestCount: 0,
3528
- errorCount: 0,
3529
- retryCount: 0,
3530
- authenticationCount: 0,
3531
- authenticationErrorCount: 0,
3532
- authenticationRetryCount: 0,
3533
- velocity: 0,
3534
- coreCount: 0,
3535
- timer: 0,
3536
- duration: 0,
3537
- latency: 0,
3538
- activeRequestCount: 0,
3539
- message: [],
3540
- childCount: 0,
3541
- rx: 0,
3542
- tx: 0
3543
- },
3544
- Start: () => __privateGet(this, _StartRunner2).call(this, workerEx, runnerEx),
3545
- Stop: () => __privateGet(this, _StopRunner2).call(this, workerEx, runnerEx),
3546
- Pause: () => __privateGet(this, _PauseRunner2).call(this, workerEx, runnerEx),
3547
- Resume: () => __privateGet(this, _ResumeRunner2).call(this, workerEx, runnerEx),
3548
- Reset: () => __privateGet(this, _ResetRunner2).call(this, workerEx, runnerEx),
3549
- Execute: () => __privateGet(this, _ExecuteRunner2).call(this, workerEx, runnerEx),
3550
- Terminate: () => __privateGet(this, _TerminateRunner2).call(this, workerEx, runnerEx),
3551
- Update: (runnerOptions2) => __privateGet(this, _UpdateRunner2).call(this, workerEx, runnerEx, runnerOptions2),
3552
- on: (eventName, cb) => {
3553
- if (!workerEx.runnersEvents[runnerEx.id]) {
3554
- workerEx.runnersEvents[runnerEx.id] = [];
3555
- }
3556
- workerEx.runnersEvents[runnerEx.id].push({
3557
- eventName,
3558
- cb
3559
- });
3560
- return runnerEx;
3561
- },
3562
- archived: false
3563
- };
3564
3435
  return runnerEx;
3565
- });
3566
- __privateAdd(this, _PostMessageToWorkerUsingDefaultChannel, (workerEx, command, payload, transferObject) => {
3436
+ } catch (error) {
3437
+ this.#error(`AddRunnerToWorker(): Error: [${error}]`);
3438
+ throw error;
3439
+ }
3440
+ };
3441
+ #SetRunnerIntoWorker = async (workerEx, runnerEx) => {
3442
+ return new Promise((resolve, reject) => {
3567
3443
  try {
3568
- if (transferObject) {
3569
- __privateGet(this, _debug2).call(this, `#PostMessageToWorker with transfer object`);
3570
- workerEx.worker.postMessage({ command, payload }, [transferObject]);
3571
- __privateGet(this, _debug2).call(this, `#PostMessageToWorker with transfer object - done...`);
3572
- } else {
3573
- __privateGet(this, _debug2).call(this, `#PostMessageToWorker`);
3574
- workerEx.worker.postMessage({ command, payload });
3575
- }
3444
+ const command = eIWMessageCommands.AddRunner;
3445
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3446
+ const payload = {
3447
+ messageId,
3448
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3449
+ };
3450
+ workerEx.messagePort.postMessage({ command, payload });
3576
3451
  } catch (error) {
3577
- __privateGet(this, _error2).call(this, `PostMessageToWorkerUsingDefaultChannel(): Error: [${error}]`);
3452
+ this.#error(`#PauseRunner(): Error: [${error}]`);
3578
3453
  throw error;
3579
3454
  }
3580
3455
  });
3581
- __privateAdd(this, _StartRunner2, async (workerEx, runnerEx) => {
3582
- return new Promise((resolve, reject) => {
3583
- try {
3584
- const command = eIWMessageCommands.StartRunner;
3585
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3586
- const payload = {
3587
- messageId,
3588
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3589
- };
3590
- workerEx.messagePort.postMessage({ command, payload });
3591
- } catch (error) {
3592
- __privateGet(this, _error2).call(this, `#StartRunner(): Error: [${error}]`);
3593
- throw error;
3594
- }
3595
- });
3596
- });
3597
- __privateAdd(this, _StopRunner2, async (workerEx, runnerEx) => {
3598
- return new Promise((resolve, reject) => {
3599
- try {
3600
- const command = eIWMessageCommands.StopRunner;
3601
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3602
- const payload = {
3603
- messageId,
3604
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3605
- };
3606
- workerEx.messagePort.postMessage({ command, payload });
3607
- } catch (error) {
3608
- __privateGet(this, _error2).call(this, `#StopRunner(): Error: [${error}]`);
3609
- throw error;
3610
- }
3611
- });
3612
- });
3613
- __privateAdd(this, _ResetRunner2, async (workerEx, runnerEx) => {
3614
- return new Promise((resolve, reject) => {
3615
- try {
3616
- const command = eIWMessageCommands.ResetRunner;
3617
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3618
- const payload = {
3619
- messageId,
3620
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3621
- };
3622
- workerEx.messagePort.postMessage({ command, payload });
3623
- } catch (error) {
3624
- __privateGet(this, _error2).call(this, `#ResetRunner(): Error: [${error}]`);
3625
- throw error;
3626
- }
3627
- });
3628
- });
3629
- __privateAdd(this, _ExecuteRunner2, async (workerEx, runnerEx) => {
3630
- return new Promise((resolve, reject) => {
3631
- try {
3632
- const command = eIWMessageCommands.ExecuteRunner;
3633
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3634
- const payload = {
3635
- messageId,
3636
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3637
- };
3638
- workerEx.messagePort.postMessage({ command, payload });
3639
- } catch (error) {
3640
- __privateGet(this, _error2).call(this, `#ExecuteRunner(): Error: [${error}]`);
3641
- throw error;
3642
- }
3643
- });
3644
- });
3645
- __privateAdd(this, _TerminateRunner2, async (workerEx, runnerEx) => {
3646
- return new Promise((resolve, reject) => {
3647
- try {
3648
- const command = eIWMessageCommands.TerminateRunner;
3649
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3650
- const payload = {
3651
- messageId,
3652
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3653
- };
3654
- workerEx.messagePort.postMessage({ command, payload });
3655
- } catch (error) {
3656
- __privateGet(this, _error2).call(this, `#PauseRunner(): Error: [${error}]`);
3657
- throw error;
3658
- }
3659
- });
3660
- });
3661
- __privateAdd(this, _PauseRunner2, async (workerEx, runnerEx) => {
3662
- return new Promise((resolve, reject) => {
3663
- try {
3664
- const command = eIWMessageCommands.PauseRunner;
3665
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3666
- const payload = {
3667
- messageId,
3668
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3669
- };
3670
- workerEx.messagePort.postMessage({ command, payload });
3671
- } catch (error) {
3672
- __privateGet(this, _error2).call(this, `#PauseRunner(): Error: [${error}]`);
3673
- throw error;
3674
- }
3675
- });
3676
- });
3677
- __privateAdd(this, _ResumeRunner2, async (workerEx, runnerEx) => {
3678
- return new Promise((resolve, reject) => {
3679
- try {
3680
- const command = eIWMessageCommands.ResumeRunner;
3681
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3682
- const payload = {
3683
- messageId,
3684
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3685
- };
3686
- workerEx.messagePort.postMessage({ command, payload });
3687
- } catch (error) {
3688
- __privateGet(this, _error2).call(this, `#ResumeRunner(): Error: [${error}]`);
3689
- throw error;
3456
+ };
3457
+ #ProcessTelemetry = (workerEx, payloadContents) => {
3458
+ try {
3459
+ const { runner } = payloadContents;
3460
+ if (workerEx.runnersEx[runner.id]) {
3461
+ const runnerEx = workerEx.runnersEx[runner.id];
3462
+ this.#SyncRunnerData(runnerEx, runner);
3463
+ if (runnerEx.publishInstrumentController && this.#telemetryProcessor) {
3464
+ this.#telemetryProcessor.ProcessTelemetry(runnerEx.publishInstrumentController, runnerEx.instrumentData);
3690
3465
  }
3691
- });
3692
- });
3693
- __privateAdd(this, _UpdateRunner2, async (workerEx, runnerEx, runnerOptions) => {
3694
- return new Promise((resolve, reject) => {
3695
- try {
3696
- merge(runnerEx.options, runnerOptions);
3697
- const command = eIWMessageCommands.UpdateRunner;
3698
- const messageId = __privateGet(this, _SetupCallbackMessage).call(this, resolve, reject, command);
3699
- const payload = {
3700
- messageId,
3701
- runner: this.CreateRunnerCopyNoHistory(runnerEx)
3702
- };
3703
- workerEx.messagePort.postMessage({ command, payload });
3704
- } catch (error) {
3705
- __privateGet(this, _error2).call(this, `#UpdateRunner(): Error: [${error}]`);
3706
- throw error;
3466
+ this.#EmitRunnerEvent("Telemetry", workerEx, runner.id);
3467
+ }
3468
+ } catch (error) {
3469
+ this.#error(`ProcessTelemetry(): Error: [${error}]`);
3470
+ throw error;
3471
+ }
3472
+ };
3473
+ #EmitWorkerEvent = (eventName, workerEx) => {
3474
+ try {
3475
+ workerEx.workerEvents.forEach((ev) => {
3476
+ if (ev.eventName.localeCompare(eventName) === 0) {
3477
+ ev.cb(workerEx);
3707
3478
  }
3708
3479
  });
3709
- });
3710
- __privateAdd(this, _StartWorker, async (workerEx) => {
3711
- const runners = Object.values(workerEx.runnersEx);
3712
- const promArray = [];
3713
- for (let i = 0; i < runners.length; i++) {
3714
- promArray.push(runners[i].Start());
3715
- }
3716
- return Promise.all(promArray);
3717
- });
3718
- __privateAdd(this, _StopWorker, async (workerEx) => {
3719
- const runners = Object.values(workerEx.runnersEx);
3720
- const promArray = [];
3721
- for (let i = 0; i < runners.length; i++) {
3722
- promArray.push(runners[i].Stop());
3723
- }
3724
- return Promise.all(promArray);
3725
- });
3726
- __privateAdd(this, _PauseWorker, async (workerEx) => {
3727
- const runners = Object.values(workerEx.runnersEx);
3728
- const promArray = [];
3729
- for (let i = 0; i < runners.length; i++) {
3730
- promArray.push(runners[i].Pause());
3731
- }
3732
- return Promise.all(promArray);
3733
- });
3734
- __privateAdd(this, _ResumeWorker, async (workerEx) => {
3735
- const runners = Object.values(workerEx.runnersEx);
3736
- const promArray = [];
3737
- for (let i = 0; i < runners.length; i++) {
3738
- promArray.push(runners[i].Resume());
3739
- }
3740
- return Promise.all(promArray);
3741
- });
3742
- __privateAdd(this, _ResetWorker, async (workerEx) => {
3743
- const runners = Object.values(workerEx.runnersEx);
3744
- const promArray = [];
3745
- for (let i = 0; i < runners.length; i++) {
3746
- promArray.push(runners[i].Reset());
3747
- }
3748
- return Promise.all(promArray);
3749
- });
3750
- __privateAdd(this, _ExecuteWorker, async (workerEx) => {
3751
- const runners = Object.values(workerEx.runnersEx);
3752
- const promArray = [];
3753
- for (let i = 0; i < runners.length; i++) {
3754
- promArray.push(runners[i].Execute());
3755
- }
3756
- return Promise.all(promArray);
3757
- });
3758
- // IExecutionProfile
3759
- __privateAdd(this, _UpdateOptionsWorker, async (workerEx, runnerOptions) => {
3760
- const runners = Object.values(workerEx.runnersEx);
3761
- const promArray = [];
3762
- for (let i = 0; i < runners.length; i++) {
3763
- promArray.push(runners[i].Update(runnerOptions));
3480
+ } catch (error) {
3481
+ this.#error(`EmitWorkerEvent(): Error: [${error}]`);
3482
+ throw error;
3483
+ }
3484
+ };
3485
+ #EmitRunnerEvent = (eventName, workerEx, runnerId) => {
3486
+ try {
3487
+ if (workerEx.runnersEvents[runnerId]) {
3488
+ const runnersEvents = workerEx.runnersEvents[runnerId];
3489
+ runnersEvents.forEach((ev) => {
3490
+ if (ev.eventName.localeCompare(eventName) === 0) {
3491
+ ev.cb(workerEx.runnersEx[runnerId]);
3492
+ }
3493
+ });
3764
3494
  }
3765
- return Promise.all(promArray);
3766
- });
3767
- __privateAdd(this, _TerminateWorker, async (workerEx) => {
3768
- try {
3769
- const runners = Object.values(workerEx.runnersEx);
3770
- const promArray = [];
3771
- for (let i = 0; i < runners.length; i++) {
3772
- promArray.push(runners[i].Terminate());
3495
+ } catch (error) {
3496
+ this.#error(`EmitRunnerEvent(): Error: [${error}]`);
3497
+ throw error;
3498
+ }
3499
+ };
3500
+ //@@ make this have an event
3501
+ //@@ make refactor event to own method
3502
+ //@@ check for other events to capture
3503
+ #RunnerStateChange = (workerEx, payloadContents) => {
3504
+ try {
3505
+ const { runner } = payloadContents;
3506
+ if (workerEx.runnersEx[runner.id]) {
3507
+ const runnerEx = workerEx.runnersEx[runner.id];
3508
+ const previousState = runnerEx.state;
3509
+ runnerEx.state = runner.state;
3510
+ if (!runnerEx.runnerHistory) {
3511
+ runnerEx.runnerHistory = [];
3773
3512
  }
3774
- const retVal = Promise.all(promArray);
3775
- if (workerEx.worker) {
3776
- setTimeout(() => {
3777
- workerEx.worker.terminate();
3778
- __privateGet(this, _debug2).call(this, `Terminated worker: [${workerEx.id}]`);
3779
- if (__privateGet(this, _workersEx)[workerEx.id]) {
3780
- delete __privateGet(this, _workersEx)[workerEx.id];
3781
- __privateGet(this, _debug2).call(this, chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker: [${workerEx.id}] has been removed from the worker collection.`));
3782
- }
3783
- }, 500);
3513
+ runnerEx.runnerHistory.push({
3514
+ eventDate: /* @__PURE__ */ new Date(),
3515
+ runner: { ...runner }
3516
+ });
3517
+ this.#SyncRunnerData(runnerEx, runner);
3518
+ this.#debug(`STSWorkerManager:#RunnerStateChange(): Worker: [${workerEx.id}] Runner: [${runner.id}] Previous State: [${previousState}] State: [${runner.state}]`);
3519
+ this.#EmitRunnerEvent("StateChange", workerEx, runner.id);
3520
+ }
3521
+ } catch (error) {
3522
+ this.#error(`RunnerStateChange(): Error: [${error}]`);
3523
+ throw error;
3524
+ }
3525
+ };
3526
+ #CreateAsyncRunner = (workerEx, runnerOptions) => {
3527
+ const runnerId = v4();
3528
+ if (this.#STSInstrumentController) {
3529
+ this.#STSInstrumentController.LogEx(chalk.yellow(`Creating new async runner: [${runnerId}]`));
3530
+ }
3531
+ const asyncRunnerContext = {
3532
+ // [level1]@[level2]^[level3]|[level4]
3533
+ // [hostName]@[agentId]-[userAgent]^[workerId]|[runnerId]
3534
+ nid: `${workerEx.options.hostName}${stsutils.ModelDelimeter.COMPONENT_SEPERATOR}${workerEx.options.agentId}-${workerEx.options.userAgent}${stsutils.ModelDelimeter.NID_SEPERATOR}${workerEx.id}${stsutils.ModelDelimeter.SEPERATOR}${runnerId}`,
3535
+ hostName: workerEx.options.hostName,
3536
+ // level 1 (e.g. host name)
3537
+ agentName: `${workerEx.options.agentId}-${workerEx.options.userAgent}`,
3538
+ // level 2 (e.g. service instance ID or user agent type and tab or instance)
3539
+ threadId: `${workerEx.id}`,
3540
+ // level 3 (web worker)
3541
+ id: runnerId
3542
+ // level 4 // (async runner within a web worker)
3543
+ };
3544
+ const runnerEx = {
3545
+ id: runnerId,
3546
+ workerId: workerEx.id,
3547
+ workerManagerId: this.#id,
3548
+ state: IRunnerState.created,
3549
+ iteration: 0,
3550
+ publishInstrumentController: this.#STSInstrumentController ? this.#STSInstrumentController.AddPublishInstrumentController(asyncRunnerContext) : void 0,
3551
+ asyncRunnerContext,
3552
+ options: runnerOptions,
3553
+ runnerHistory: [],
3554
+ instrumentData: {
3555
+ requestCount: 0,
3556
+ errorCount: 0,
3557
+ retryCount: 0,
3558
+ authenticationCount: 0,
3559
+ authenticationErrorCount: 0,
3560
+ authenticationRetryCount: 0,
3561
+ velocity: 0,
3562
+ coreCount: 0,
3563
+ timer: 0,
3564
+ duration: 0,
3565
+ latency: 0,
3566
+ activeRequestCount: 0,
3567
+ message: [],
3568
+ childCount: 0,
3569
+ rx: 0,
3570
+ tx: 0
3571
+ },
3572
+ Start: () => this.#StartRunner(workerEx, runnerEx),
3573
+ Stop: () => this.#StopRunner(workerEx, runnerEx),
3574
+ Pause: () => this.#PauseRunner(workerEx, runnerEx),
3575
+ Resume: () => this.#ResumeRunner(workerEx, runnerEx),
3576
+ Reset: () => this.#ResetRunner(workerEx, runnerEx),
3577
+ Execute: () => this.#ExecuteRunner(workerEx, runnerEx),
3578
+ Terminate: () => this.#TerminateRunner(workerEx, runnerEx),
3579
+ Update: (runnerOptions2) => this.#UpdateRunner(workerEx, runnerEx, runnerOptions2),
3580
+ on: (eventName, cb) => {
3581
+ if (!workerEx.runnersEvents[runnerEx.id]) {
3582
+ workerEx.runnersEvents[runnerEx.id] = [];
3784
3583
  }
3785
- return retVal;
3786
- } catch (error) {
3787
- __privateGet(this, _error2).call(this, `TerminateWorker(): Error: [${error}]`);
3788
- return [];
3584
+ workerEx.runnersEvents[runnerEx.id].push({
3585
+ eventName,
3586
+ cb
3587
+ });
3588
+ return runnerEx;
3589
+ },
3590
+ archived: false
3591
+ };
3592
+ return runnerEx;
3593
+ };
3594
+ #PostMessageToWorkerUsingDefaultChannel = (workerEx, command, payload, transferObject) => {
3595
+ try {
3596
+ if (transferObject) {
3597
+ this.#debug(`#PostMessageToWorker with transfer object`);
3598
+ workerEx.worker.postMessage({ command, payload }, [transferObject]);
3599
+ this.#debug(`#PostMessageToWorker with transfer object - done...`);
3600
+ } else {
3601
+ this.#debug(`#PostMessageToWorker`);
3602
+ workerEx.worker.postMessage({ command, payload });
3789
3603
  }
3790
- });
3791
- __publicField(this, "GetNextAvailableWorker", () => {
3792
- __privateGet(this, _debug2).call(this, `GetNextAvailableWorker()`);
3604
+ } catch (error) {
3605
+ this.#error(`PostMessageToWorkerUsingDefaultChannel(): Error: [${error}]`);
3606
+ throw error;
3607
+ }
3608
+ };
3609
+ #StartRunner = async (workerEx, runnerEx) => {
3610
+ return new Promise((resolve, reject) => {
3793
3611
  try {
3794
- let leastRunnerWorker = null;
3795
- for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
3796
- if (leastRunnerWorker) {
3797
- if (Object.keys(stsWorker.runnersEx).length < Object.keys(leastRunnerWorker.runnersEx).length) {
3798
- leastRunnerWorker = stsWorker;
3799
- }
3800
- } else {
3801
- leastRunnerWorker = stsWorker;
3802
- }
3803
- }
3804
- return leastRunnerWorker;
3612
+ const command = eIWMessageCommands.StartRunner;
3613
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3614
+ const payload = {
3615
+ messageId,
3616
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3617
+ };
3618
+ workerEx.messagePort.postMessage({ command, payload });
3805
3619
  } catch (error) {
3806
- __privateGet(this, _error2).call(this, `GetNextAvailableWorker(): Error: [${error}]`);
3807
- return null;
3620
+ this.#error(`#StartRunner(): Error: [${error}]`);
3621
+ throw error;
3808
3622
  }
3809
3623
  });
3810
- __publicField(this, "GetBusyWorker", () => {
3811
- __privateGet(this, _debug2).call(this, `GetBusyWorker()`);
3624
+ };
3625
+ #StopRunner = async (workerEx, runnerEx) => {
3626
+ return new Promise((resolve, reject) => {
3812
3627
  try {
3813
- let busyWorker = null;
3814
- for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
3815
- if (busyWorker) {
3816
- if (Object.keys(stsWorker.runnersEx).length > Object.keys(busyWorker.runnersEx).length) {
3817
- busyWorker = stsWorker;
3818
- }
3819
- } else {
3820
- busyWorker = stsWorker;
3821
- }
3822
- }
3823
- return busyWorker;
3628
+ const command = eIWMessageCommands.StopRunner;
3629
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3630
+ const payload = {
3631
+ messageId,
3632
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3633
+ };
3634
+ workerEx.messagePort.postMessage({ command, payload });
3824
3635
  } catch (error) {
3825
- __privateGet(this, _error2).call(this, `GetBusyWorker(): Error: [${error}]`);
3826
- return null;
3636
+ this.#error(`#StopRunner(): Error: [${error}]`);
3637
+ throw error;
3827
3638
  }
3828
3639
  });
3829
- __privateAdd(this, _ProcessWorkerCommands, async (workerIds, command, runnerOptions) => {
3830
- __privateGet(this, _debug2).call(this, `#ProcessWorkerCommands: workerIds: [${workerIds}] command: [${command}`);
3640
+ };
3641
+ #ResetRunner = async (workerEx, runnerEx) => {
3642
+ return new Promise((resolve, reject) => {
3831
3643
  try {
3832
- const promArray = [];
3833
- const workers = Object.values(this.WorkersEx).filter((workerEx) => workerIds.length === 0 ? true : workerIds.includes(workerEx.id));
3834
- for (let i = 0; i < workers.length; i++) {
3835
- if (command === "Update") {
3836
- promArray.push(workers[i][command](runnerOptions));
3837
- } else {
3838
- promArray.push(workers[i][command]());
3839
- }
3840
- }
3841
- const retValResult = await Promise.all(promArray);
3842
- const returnVal = [];
3843
- for (let i = 0; i < workers.length; i++) {
3844
- returnVal.push({
3845
- workerManagerId: __privateGet(this, _id),
3846
- workerId: workers[i].id,
3847
- executeRunnerActionResults: retValResult[i]
3848
- });
3849
- }
3850
- return returnVal;
3644
+ const command = eIWMessageCommands.ResetRunner;
3645
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3646
+ const payload = {
3647
+ messageId,
3648
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3649
+ };
3650
+ workerEx.messagePort.postMessage({ command, payload });
3851
3651
  } catch (error) {
3852
- __privateGet(this, _error2).call(this, `ProcessWorkerCommands(): command: [${command}] workerIds: [${workerIds}] Error: [${error}]`);
3853
- return [];
3652
+ this.#error(`#ResetRunner(): Error: [${error}]`);
3653
+ throw error;
3854
3654
  }
3855
3655
  });
3856
- __publicField(this, "StartWorkers", async (workerIds) => {
3857
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Start");
3858
- });
3859
- __publicField(this, "StopWorkers", async (workerIds) => {
3860
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Stop");
3861
- });
3862
- __publicField(this, "PauseWorkers", async (workerIds) => {
3863
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Pause");
3864
- });
3865
- __publicField(this, "ResumeWorkers", async (workerIds) => {
3866
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Resume");
3867
- });
3868
- __publicField(this, "ExecuteWorkers", async (workerIds) => {
3869
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Execute");
3870
- });
3871
- __publicField(this, "ResetWorkers", async (workerIds) => {
3872
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Reset");
3873
- });
3874
- __publicField(this, "TerminateWorkers", async (workerIds) => {
3875
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Terminate");
3876
- });
3877
- __publicField(this, "UpdateWorkers", async (workerIds, runnerOptions) => {
3878
- return __privateGet(this, _ProcessWorkerCommands).call(this, workerIds, "Update", runnerOptions);
3879
- });
3880
- __privateAdd(this, _ExecuteVariableCommandOnRunners, async (workerId, runnerIds, command, runnerOptions) => {
3881
- __privateGet(this, _debug2).call(this, `#ExecuteVariableCommandOnRunners: workerId: [${workerId}] command: [${command} runnerIds: [${runnerIds}]`);
3656
+ };
3657
+ #ExecuteRunner = async (workerEx, runnerEx) => {
3658
+ return new Promise((resolve, reject) => {
3882
3659
  try {
3883
- if (__privateGet(this, _workersEx)[workerId]) {
3884
- if (runnerIds.length === 0) {
3885
- if (command === "Update") {
3886
- return __privateGet(this, _workersEx)[workerId][command](runnerOptions);
3887
- } else {
3888
- return __privateGet(this, _workersEx)[workerId][command]();
3889
- }
3890
- } else {
3891
- const promArray = [];
3892
- const runners = Object.values(__privateGet(this, _workersEx)[workerId].runnersEx).filter((runnerEx) => runnerIds.length === 0 ? true : runnerIds.includes(runnerEx.id));
3893
- for (let i = 0; i < runners.length; i++) {
3894
- if (command === "Update") {
3895
- promArray.push(runners[i][command](runnerOptions));
3896
- } else {
3897
- promArray.push(runners[i][command]());
3898
- }
3899
- }
3900
- const retValResult = await Promise.all(promArray);
3901
- const returnVal = [];
3902
- for (let i = 0; i < runners.length; i++) {
3903
- returnVal.push({ ...retValResult[i] });
3904
- }
3905
- return returnVal;
3906
- }
3907
- }
3908
- return [];
3660
+ const command = eIWMessageCommands.ExecuteRunner;
3661
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3662
+ const payload = {
3663
+ messageId,
3664
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3665
+ };
3666
+ workerEx.messagePort.postMessage({ command, payload });
3909
3667
  } catch (error) {
3910
- __privateGet(this, _error2).call(this, `#ExecuteVariableCommandRunners(): command: [${command}] workerId: [${workerId}] runnerIds: [${runnerIds}] Error: [${error}]`);
3911
- return [];
3668
+ this.#error(`#ExecuteRunner(): Error: [${error}]`);
3669
+ throw error;
3912
3670
  }
3913
3671
  });
3914
- __publicField(this, "StopRunners", async (workerId, runnerIds) => {
3915
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Stop");
3916
- });
3917
- __publicField(this, "StartRunners", async (workerId, runnerIds) => {
3918
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Start");
3919
- });
3920
- __publicField(this, "PauseRunners", async (workerId, runnerIds) => {
3921
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Pause");
3922
- });
3923
- __publicField(this, "ResumeRunners", async (workerId, runnerIds) => {
3924
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Resume");
3925
- });
3926
- __publicField(this, "ExecuteRunners", async (workerId, runnerIds) => {
3927
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Execute");
3928
- });
3929
- __publicField(this, "ResetRunners", async (workerId, runnerIds) => {
3930
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Reset");
3931
- });
3932
- __publicField(this, "TerminateRunners", async (workerId, runnerIds) => {
3933
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Terminate");
3934
- });
3935
- __publicField(this, "UpdateRunners", async (workerId, runnerIds, runnerOptions) => {
3936
- return __privateGet(this, _ExecuteVariableCommandOnRunners).call(this, workerId, runnerIds, "Update", runnerOptions);
3937
- });
3938
- __privateAdd(this, _SyncRunnerData, (runnerEx, runner) => {
3672
+ };
3673
+ #TerminateRunner = async (workerEx, runnerEx) => {
3674
+ return new Promise((resolve, reject) => {
3939
3675
  try {
3940
- runnerEx.iteration = runner.iteration;
3941
- runnerEx.state = runner.state;
3942
- runnerEx.instrumentData = { ...runner.instrumentData };
3676
+ const command = eIWMessageCommands.TerminateRunner;
3677
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3678
+ const payload = {
3679
+ messageId,
3680
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3681
+ };
3682
+ workerEx.messagePort.postMessage({ command, payload });
3943
3683
  } catch (error) {
3944
- __privateGet(this, _error2).call(this, `#SyncRunnerData(): Error: [${error}]`);
3684
+ this.#error(`#PauseRunner(): Error: [${error}]`);
3685
+ throw error;
3945
3686
  }
3946
3687
  });
3947
- __privateAdd(this, _SyncWorkerDataFromPayload, (payload) => {
3688
+ };
3689
+ #PauseRunner = async (workerEx, runnerEx) => {
3690
+ return new Promise((resolve, reject) => {
3948
3691
  try {
3949
- if (__privateGet(this, _workersEx)[payload.workerId]) {
3950
- const runnersEx = __privateGet(this, _workersEx)[payload.workerId].runnersEx;
3951
- if (runnersEx) {
3952
- payload.runners.forEach((runner) => {
3953
- if (runnersEx[runner.id]) {
3954
- __privateGet(this, _SyncRunnerData).call(this, runnersEx[runner.id], runner);
3955
- }
3956
- });
3957
- }
3958
- }
3692
+ const command = eIWMessageCommands.PauseRunner;
3693
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3694
+ const payload = {
3695
+ messageId,
3696
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3697
+ };
3698
+ workerEx.messagePort.postMessage({ command, payload });
3959
3699
  } catch (error) {
3960
- __privateGet(this, _error2).call(this, `#SyncWorkerDataFromPayload(): Error: [${error}]`);
3700
+ this.#error(`#PauseRunner(): Error: [${error}]`);
3701
+ throw error;
3961
3702
  }
3962
3703
  });
3963
- __privateAdd(this, _SyncWorkerDataFromWorker, async (workerEx) => {
3704
+ };
3705
+ #ResumeRunner = async (workerEx, runnerEx) => {
3706
+ return new Promise((resolve, reject) => {
3964
3707
  try {
3965
- const retVal = await __privateGet(this, _PostMessageToWorkerGetRunners).call(this, workerEx, eIWMessageCommands.GetRunners);
3966
- __privateGet(this, _SyncWorkerDataFromPayload).call(this, retVal.payload);
3967
- return retVal;
3708
+ const command = eIWMessageCommands.ResumeRunner;
3709
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3710
+ const payload = {
3711
+ messageId,
3712
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3713
+ };
3714
+ workerEx.messagePort.postMessage({ command, payload });
3968
3715
  } catch (error) {
3969
- __privateGet(this, _error2).call(this, `#SyncWorkerDataFromWorker(): Error: [${error}]`);
3716
+ this.#error(`#ResumeRunner(): Error: [${error}]`);
3970
3717
  throw error;
3971
3718
  }
3972
3719
  });
3973
- __privateAdd(this, _SyncWorkerDataFromWorkers, async () => {
3720
+ };
3721
+ #UpdateRunner = async (workerEx, runnerEx, runnerOptions) => {
3722
+ return new Promise((resolve, reject) => {
3974
3723
  try {
3975
- const retVal = await Promise.all(Object.values(__privateGet(this, _workersEx)).map((workerEx) => __privateGet(this, _PostMessageToWorkerGetRunners).call(this, workerEx, eIWMessageCommands.GetRunners)));
3976
- retVal.forEach((messagePayload) => {
3977
- __privateGet(this, _SyncWorkerDataFromPayload).call(this, messagePayload.payload);
3978
- });
3979
- return retVal;
3724
+ merge(runnerEx.options, runnerOptions);
3725
+ const command = eIWMessageCommands.UpdateRunner;
3726
+ const messageId = this.#SetupCallbackMessage(resolve, reject, command);
3727
+ const payload = {
3728
+ messageId,
3729
+ runner: this.CreateRunnerCopyNoHistory(runnerEx)
3730
+ };
3731
+ workerEx.messagePort.postMessage({ command, payload });
3980
3732
  } catch (error) {
3981
- __privateGet(this, _error2).call(this, `#SyncWorkerDataFromWorkers(): Error: [${error}]`);
3733
+ this.#error(`#UpdateRunner(): Error: [${error}]`);
3982
3734
  throw error;
3983
3735
  }
3984
3736
  });
3985
- __privateAdd(this, _SetupCallbackMessage, (resolve, reject, command) => {
3986
- const messageId = v4();
3987
- __privateGet(this, _messages)[messageId] = {
3988
- timeout: setTimeout(() => {
3989
- delete __privateGet(this, _messages)[messageId];
3990
- reject(`STSWorkerManager:#SetupCallbackMessage(): message response timeout for message id: [${messageId}], command: [${command}]`);
3991
- }, __privateGet(this, _options2).messageTimeout),
3992
- resolveMessage: (payload) => {
3993
- resolve(payload);
3994
- }
3995
- };
3996
- return messageId;
3997
- });
3998
- __privateAdd(this, _PostMessageToWorkerGetRunners, async (workerEx, command) => {
3999
- return new Promise((resolve, reject) => {
4000
- try {
4001
- const messageId = v4();
4002
- __privateGet(this, _messages)[messageId] = {
4003
- timeout: setTimeout(() => {
4004
- delete __privateGet(this, _messages)[messageId];
4005
- reject(`STSWorkerManager:#PostMessageToWorkerGetRunners(): message response timeout for message id: [${messageId}], command: [${command}]`);
4006
- }, __privateGet(this, _options2).messageTimeout),
4007
- resolveMessage: (payload2) => {
4008
- resolve(payload2);
4009
- }
4010
- };
4011
- const payload = {
4012
- messageId
4013
- };
4014
- workerEx.messagePort.postMessage({ command, payload });
4015
- } catch (error) {
4016
- __privateGet(this, _error2).call(this, `#PostMessageToWorkerGetRunners(): Error: [${error}]`);
4017
- }
4018
- });
4019
- });
4020
- __privateSet(this, _id, v4());
4021
- if (options) {
4022
- __privateSet(this, _options2, options);
4023
- } else {
4024
- __privateSet(this, _options2, {});
3737
+ };
3738
+ #StartWorker = async (workerEx) => {
3739
+ const runners = Object.values(workerEx.runnersEx);
3740
+ const promArray = [];
3741
+ for (let i = 0; i < runners.length; i++) {
3742
+ promArray.push(runners[i].Start());
3743
+ }
3744
+ return Promise.all(promArray);
3745
+ };
3746
+ #StopWorker = async (workerEx) => {
3747
+ const runners = Object.values(workerEx.runnersEx);
3748
+ const promArray = [];
3749
+ for (let i = 0; i < runners.length; i++) {
3750
+ promArray.push(runners[i].Stop());
4025
3751
  }
4026
- if (__privateGet(this, _options2).publishInstrumentController) {
4027
- __privateSet(this, _STSInstrumentController, __privateGet(this, _options2).publishInstrumentController);
4028
- __privateSet(this, _telemetryProcessor, new TelemetryProcessor());
3752
+ return Promise.all(promArray);
3753
+ };
3754
+ #PauseWorker = async (workerEx) => {
3755
+ const runners = Object.values(workerEx.runnersEx);
3756
+ const promArray = [];
3757
+ for (let i = 0; i < runners.length; i++) {
3758
+ promArray.push(runners[i].Pause());
4029
3759
  }
4030
- __privateGet(this, _processLoopExecutor2).call(this);
4031
- }
4032
- CreateRunnerCopyNoHistory(runnerEx) {
3760
+ return Promise.all(promArray);
3761
+ };
3762
+ #ResumeWorker = async (workerEx) => {
3763
+ const runners = Object.values(workerEx.runnersEx);
3764
+ const promArray = [];
3765
+ for (let i = 0; i < runners.length; i++) {
3766
+ promArray.push(runners[i].Resume());
3767
+ }
3768
+ return Promise.all(promArray);
3769
+ };
3770
+ #ResetWorker = async (workerEx) => {
3771
+ const runners = Object.values(workerEx.runnersEx);
3772
+ const promArray = [];
3773
+ for (let i = 0; i < runners.length; i++) {
3774
+ promArray.push(runners[i].Reset());
3775
+ }
3776
+ return Promise.all(promArray);
3777
+ };
3778
+ #ExecuteWorker = async (workerEx) => {
3779
+ const runners = Object.values(workerEx.runnersEx);
3780
+ const promArray = [];
3781
+ for (let i = 0; i < runners.length; i++) {
3782
+ promArray.push(runners[i].Execute());
3783
+ }
3784
+ return Promise.all(promArray);
3785
+ };
3786
+ // IExecutionProfile
3787
+ #UpdateOptionsWorker = async (workerEx, runnerOptions) => {
3788
+ const runners = Object.values(workerEx.runnersEx);
3789
+ const promArray = [];
3790
+ for (let i = 0; i < runners.length; i++) {
3791
+ promArray.push(runners[i].Update(runnerOptions));
3792
+ }
3793
+ return Promise.all(promArray);
3794
+ };
3795
+ #TerminateWorker = async (workerEx) => {
4033
3796
  try {
4034
- return {
4035
- id: runnerEx.id,
4036
- asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
4037
- instrumentData: { ...runnerEx.instrumentData },
4038
- iteration: runnerEx.iteration,
4039
- options: { ...runnerEx.options },
4040
- state: runnerEx.state,
4041
- workerId: runnerEx.workerId,
4042
- workerManagerId: __privateGet(this, _id)
4043
- };
3797
+ const runners = Object.values(workerEx.runnersEx);
3798
+ const promArray = [];
3799
+ for (let i = 0; i < runners.length; i++) {
3800
+ promArray.push(runners[i].Terminate());
3801
+ }
3802
+ const retVal = Promise.all(promArray);
3803
+ if (workerEx.worker) {
3804
+ setTimeout(() => {
3805
+ workerEx.worker.terminate();
3806
+ this.#debug(`Terminated worker: [${workerEx.id}]`);
3807
+ if (this.#workersEx[workerEx.id]) {
3808
+ delete this.#workersEx[workerEx.id];
3809
+ this.#debug(chalk.magenta(`STSWorkerManager:stsWorkerEx.worker.on(exit): Worker: [${workerEx.id}] has been removed from the worker collection.`));
3810
+ }
3811
+ }, 500);
3812
+ }
3813
+ return retVal;
4044
3814
  } catch (error) {
4045
- __privateGet(this, _error2).call(this, `CreateRunnerCopyNoHistory(): Error: [${error}]`);
4046
- throw error;
3815
+ this.#error(`TerminateWorker(): Error: [${error}]`);
3816
+ return [];
4047
3817
  }
4048
- }
4049
- CreateRunnerCopy(runnerEx) {
3818
+ };
3819
+ GetNextAvailableWorker = () => {
3820
+ this.#debug(`GetNextAvailableWorker()`);
4050
3821
  try {
4051
- const retVal = this.CreateRunnerCopyNoHistory(runnerEx);
4052
- if (runnerEx.runnerHistory) {
4053
- retVal.runnerHistory = [...runnerEx.runnerHistory];
3822
+ let leastRunnerWorker = null;
3823
+ for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
3824
+ if (leastRunnerWorker) {
3825
+ if (Object.keys(stsWorker.runnersEx).length < Object.keys(leastRunnerWorker.runnersEx).length) {
3826
+ leastRunnerWorker = stsWorker;
3827
+ }
3828
+ } else {
3829
+ leastRunnerWorker = stsWorker;
3830
+ }
4054
3831
  }
4055
- return retVal;
3832
+ return leastRunnerWorker;
4056
3833
  } catch (error) {
4057
- __privateGet(this, _error2).call(this, `CreateRunnerCopy(): Error: [${error}]`);
4058
- throw error;
3834
+ this.#error(`GetNextAvailableWorker(): Error: [${error}]`);
3835
+ return null;
4059
3836
  }
4060
- }
4061
- CreateRunnerCopySmall(runnerEx) {
3837
+ };
3838
+ GetBusyWorker = () => {
3839
+ this.#debug(`GetBusyWorker()`);
4062
3840
  try {
4063
- const retVal = {
4064
- id: runnerEx.id,
4065
- iteration: runnerEx.iteration,
4066
- state: runnerEx.state
4067
- };
4068
- if (runnerEx.options && runnerEx.options.runnerPlan) {
4069
- retVal.options = {
4070
- runnerPlan: { ...runnerEx.options.runnerPlan }
4071
- };
3841
+ let busyWorker = null;
3842
+ for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
3843
+ if (busyWorker) {
3844
+ if (Object.keys(stsWorker.runnersEx).length > Object.keys(busyWorker.runnersEx).length) {
3845
+ busyWorker = stsWorker;
3846
+ }
3847
+ } else {
3848
+ busyWorker = stsWorker;
3849
+ }
4072
3850
  }
4073
- return retVal;
3851
+ return busyWorker;
4074
3852
  } catch (error) {
4075
- __privateGet(this, _error2).call(this, `CreateRunnerCopy(): Error: [${error}]`);
4076
- throw error;
3853
+ this.#error(`GetBusyWorker(): Error: [${error}]`);
3854
+ return null;
4077
3855
  }
3856
+ };
3857
+ get Options() {
3858
+ return this.#options;
4078
3859
  }
4079
- CreateWorkerCopy(workerEx) {
3860
+ set Options(options) {
3861
+ this.#options = options;
3862
+ }
3863
+ #ProcessWorkerCommands = async (workerIds, command, runnerOptions) => {
3864
+ this.#debug(`#ProcessWorkerCommands: workerIds: [${workerIds}] command: [${command}`);
4080
3865
  try {
4081
- const { id, options, runnersEx, workerManagerId } = workerEx;
4082
- const workerCopy = {
4083
- id,
4084
- options: { ...options },
4085
- runners: {},
4086
- workerManagerId
4087
- };
4088
- for (const [, runnerEx] of Object.entries(runnersEx)) {
4089
- workerCopy.runners[runnerEx.id] = this.CreateRunnerCopy(runnerEx);
3866
+ const promArray = [];
3867
+ const workers = Object.values(this.WorkersEx).filter((workerEx) => workerIds.length === 0 ? true : workerIds.includes(workerEx.id));
3868
+ for (let i = 0; i < workers.length; i++) {
3869
+ if (command === "Update") {
3870
+ promArray.push(workers[i][command](runnerOptions));
3871
+ } else {
3872
+ promArray.push(workers[i][command]());
3873
+ }
4090
3874
  }
4091
- return workerCopy;
3875
+ const retValResult = await Promise.all(promArray);
3876
+ const returnVal = [];
3877
+ for (let i = 0; i < workers.length; i++) {
3878
+ returnVal.push({
3879
+ workerManagerId: this.#id,
3880
+ workerId: workers[i].id,
3881
+ executeRunnerActionResults: retValResult[i]
3882
+ });
3883
+ }
3884
+ return returnVal;
4092
3885
  } catch (error) {
4093
- __privateGet(this, _error2).call(this, `#CreateWorkerCopy(): Error: [${error}]`);
4094
- throw error;
3886
+ this.#error(`ProcessWorkerCommands(): command: [${command}] workerIds: [${workerIds}] Error: [${error}]`);
3887
+ return [];
4095
3888
  }
4096
- }
4097
- CreateWorkerCopySmall(workerEx, states) {
3889
+ };
3890
+ StartWorkers = async (workerIds) => {
3891
+ return this.#ProcessWorkerCommands(workerIds, "Start");
3892
+ };
3893
+ StopWorkers = async (workerIds) => {
3894
+ return this.#ProcessWorkerCommands(workerIds, "Stop");
3895
+ };
3896
+ PauseWorkers = async (workerIds) => {
3897
+ return this.#ProcessWorkerCommands(workerIds, "Pause");
3898
+ };
3899
+ ResumeWorkers = async (workerIds) => {
3900
+ return this.#ProcessWorkerCommands(workerIds, "Resume");
3901
+ };
3902
+ ExecuteWorkers = async (workerIds) => {
3903
+ return this.#ProcessWorkerCommands(workerIds, "Execute");
3904
+ };
3905
+ ResetWorkers = async (workerIds) => {
3906
+ return this.#ProcessWorkerCommands(workerIds, "Reset");
3907
+ };
3908
+ TerminateWorkers = async (workerIds) => {
3909
+ return this.#ProcessWorkerCommands(workerIds, "Terminate");
3910
+ };
3911
+ UpdateWorkers = async (workerIds, runnerOptions) => {
3912
+ return this.#ProcessWorkerCommands(workerIds, "Update", runnerOptions);
3913
+ };
3914
+ #ExecuteVariableCommandOnRunners = async (workerId, runnerIds, command, runnerOptions) => {
3915
+ this.#debug(`#ExecuteVariableCommandOnRunners: workerId: [${workerId}] command: [${command} runnerIds: [${runnerIds}]`);
4098
3916
  try {
4099
- const workerCopy = {
4100
- id: workerEx.id,
4101
- runners: {}
4102
- };
4103
- Object.values(workerEx.runnersEx).filter((runnerEx) => states.length === 0 ? true : states.includes(runnerEx.state)).forEach((runnerEx) => {
4104
- workerCopy.runners[runnerEx.id] = this.CreateRunnerCopySmall(runnerEx);
4105
- });
4106
- return workerCopy;
3917
+ if (this.#workersEx[workerId]) {
3918
+ if (runnerIds.length === 0) {
3919
+ if (command === "Update") {
3920
+ return this.#workersEx[workerId][command](runnerOptions);
3921
+ } else {
3922
+ return this.#workersEx[workerId][command]();
3923
+ }
3924
+ } else {
3925
+ const promArray = [];
3926
+ const runners = Object.values(this.#workersEx[workerId].runnersEx).filter((runnerEx) => runnerIds.length === 0 ? true : runnerIds.includes(runnerEx.id));
3927
+ for (let i = 0; i < runners.length; i++) {
3928
+ if (command === "Update") {
3929
+ promArray.push(runners[i][command](runnerOptions));
3930
+ } else {
3931
+ promArray.push(runners[i][command]());
3932
+ }
3933
+ }
3934
+ const retValResult = await Promise.all(promArray);
3935
+ const returnVal = [];
3936
+ for (let i = 0; i < runners.length; i++) {
3937
+ returnVal.push({ ...retValResult[i] });
3938
+ }
3939
+ return returnVal;
3940
+ }
3941
+ }
3942
+ return [];
4107
3943
  } catch (error) {
4108
- __privateGet(this, _error2).call(this, `CreateWorkerCopySmall(): Error: [${error}]`);
4109
- throw error;
3944
+ this.#error(`#ExecuteVariableCommandRunners(): command: [${command}] workerId: [${workerId}] runnerIds: [${runnerIds}] Error: [${error}]`);
3945
+ return [];
3946
+ }
3947
+ };
3948
+ StopRunners = async (workerId, runnerIds) => {
3949
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Stop");
3950
+ };
3951
+ StartRunners = async (workerId, runnerIds) => {
3952
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Start");
3953
+ };
3954
+ PauseRunners = async (workerId, runnerIds) => {
3955
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Pause");
3956
+ };
3957
+ ResumeRunners = async (workerId, runnerIds) => {
3958
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Resume");
3959
+ };
3960
+ ExecuteRunners = async (workerId, runnerIds) => {
3961
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Execute");
3962
+ };
3963
+ ResetRunners = async (workerId, runnerIds) => {
3964
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Reset");
3965
+ };
3966
+ TerminateRunners = async (workerId, runnerIds) => {
3967
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Terminate");
3968
+ };
3969
+ UpdateRunners = async (workerId, runnerIds, runnerOptions) => {
3970
+ return this.#ExecuteVariableCommandOnRunners(workerId, runnerIds, "Update", runnerOptions);
3971
+ };
3972
+ #GetRunnersResponse(stsWorkerEx, payload) {
3973
+ try {
3974
+ const messageId = payload.messageId;
3975
+ if (this.#messages[messageId]) {
3976
+ const messageRecord = this.#messages[messageId];
3977
+ clearTimeout(messageRecord.timeout);
3978
+ const returnPayload = {
3979
+ command: eIWMessageCommands.GetRunners,
3980
+ payload: {
3981
+ messageId,
3982
+ workerId: stsWorkerEx.id,
3983
+ runners: payload.runners
3984
+ }
3985
+ };
3986
+ delete this.#messages[messageId];
3987
+ messageRecord.resolveMessage(returnPayload);
3988
+ }
3989
+ } catch (error) {
3990
+ this.#error(`#GetRunnersResponse(): Error: [${error}]`);
4110
3991
  }
4111
3992
  }
4112
- get id() {
4113
- return __privateGet(this, _id);
4114
- }
4115
- get WorkersEx() {
4116
- return __privateGet(this, _workersEx);
4117
- }
4118
- get Options() {
4119
- return __privateGet(this, _options2);
4120
- }
4121
- set Options(options) {
4122
- __privateSet(this, _options2, options);
4123
- }
4124
- }
4125
- _workersEx = new WeakMap();
4126
- _options2 = new WeakMap();
4127
- _STSInstrumentController = new WeakMap();
4128
- _telemetryProcessor = new WeakMap();
4129
- _archiveList = new WeakMap();
4130
- _id = new WeakMap();
4131
- _messages = new WeakMap();
4132
- _archiveDeleteTimeout2 = new WeakMap();
4133
- _logMessage2 = new WeakMap();
4134
- _silly2 = new WeakMap();
4135
- _debug2 = new WeakMap();
4136
- _info2 = new WeakMap();
4137
- _warn2 = new WeakMap();
4138
- _error2 = new WeakMap();
4139
- _processLoopExecutor2 = new WeakMap();
4140
- _SetRunnerIntoWorker = new WeakMap();
4141
- _ProcessTelemetry = new WeakMap();
4142
- _EmitWorkerEvent = new WeakMap();
4143
- _EmitRunnerEvent = new WeakMap();
4144
- _RunnerStateChange = new WeakMap();
4145
- _CreateAsyncRunner = new WeakMap();
4146
- _PostMessageToWorkerUsingDefaultChannel = new WeakMap();
4147
- _StartRunner2 = new WeakMap();
4148
- _StopRunner2 = new WeakMap();
4149
- _ResetRunner2 = new WeakMap();
4150
- _ExecuteRunner2 = new WeakMap();
4151
- _TerminateRunner2 = new WeakMap();
4152
- _PauseRunner2 = new WeakMap();
4153
- _ResumeRunner2 = new WeakMap();
4154
- _UpdateRunner2 = new WeakMap();
4155
- _StartWorker = new WeakMap();
4156
- _StopWorker = new WeakMap();
4157
- _PauseWorker = new WeakMap();
4158
- _ResumeWorker = new WeakMap();
4159
- _ResetWorker = new WeakMap();
4160
- _ExecuteWorker = new WeakMap();
4161
- _UpdateOptionsWorker = new WeakMap();
4162
- _TerminateWorker = new WeakMap();
4163
- _ProcessWorkerCommands = new WeakMap();
4164
- _ExecuteVariableCommandOnRunners = new WeakMap();
4165
- _STSWorkerManager_instances = new WeakSet();
4166
- GetRunnersResponse_fn = function(stsWorkerEx, payload) {
4167
- try {
4168
- const messageId = payload.messageId;
4169
- if (__privateGet(this, _messages)[messageId]) {
4170
- const messageRecord = __privateGet(this, _messages)[messageId];
4171
- clearTimeout(messageRecord.timeout);
4172
- const returnPayload = {
4173
- command: eIWMessageCommands.GetRunners,
4174
- payload: {
4175
- messageId,
4176
- workerId: stsWorkerEx.id,
4177
- runners: payload.runners
3993
+ #ProcessRunnerResponse(stsWorkerEx, payload) {
3994
+ try {
3995
+ const messageId = payload.messageId;
3996
+ if (this.#messages[messageId]) {
3997
+ const messageRecord = this.#messages[messageId];
3998
+ clearTimeout(messageRecord.timeout);
3999
+ const retPayload = { ...payload.executeRunnerActionResult };
4000
+ delete this.#messages[messageId];
4001
+ if (this.#workersEx[payload.runner.workerId]) {
4002
+ const runnersEx = this.#workersEx[payload.runner.workerId].runnersEx;
4003
+ if (runnersEx && runnersEx[payload.runner.id]) {
4004
+ this.#SyncRunnerData(runnersEx[payload.runner.id], payload.runner);
4005
+ }
4178
4006
  }
4179
- };
4180
- delete __privateGet(this, _messages)[messageId];
4181
- messageRecord.resolveMessage(returnPayload);
4007
+ messageRecord.resolveMessage(retPayload);
4008
+ }
4009
+ } catch (error) {
4010
+ this.#error(`#ProcessRunnerResponse(): Error: [${error}]`);
4182
4011
  }
4183
- } catch (error) {
4184
- __privateGet(this, _error2).call(this, `#GetRunnersResponse(): Error: [${error}]`);
4185
4012
  }
4186
- };
4187
- ProcessRunnerResponse_fn = function(stsWorkerEx, payload) {
4188
- try {
4189
- const messageId = payload.messageId;
4190
- if (__privateGet(this, _messages)[messageId]) {
4191
- const messageRecord = __privateGet(this, _messages)[messageId];
4192
- clearTimeout(messageRecord.timeout);
4193
- const retPayload = { ...payload.executeRunnerActionResult };
4194
- delete __privateGet(this, _messages)[messageId];
4195
- if (__privateGet(this, _workersEx)[payload.runner.workerId]) {
4196
- const runnersEx = __privateGet(this, _workersEx)[payload.runner.workerId].runnersEx;
4197
- if (runnersEx && runnersEx[payload.runner.id]) {
4198
- __privateGet(this, _SyncRunnerData).call(this, runnersEx[payload.runner.id], payload.runner);
4013
+ #SyncRunnerData = (runnerEx, runner) => {
4014
+ try {
4015
+ runnerEx.iteration = runner.iteration;
4016
+ runnerEx.state = runner.state;
4017
+ runnerEx.instrumentData = { ...runner.instrumentData };
4018
+ } catch (error) {
4019
+ this.#error(`#SyncRunnerData(): Error: [${error}]`);
4020
+ }
4021
+ };
4022
+ #SyncWorkerDataFromPayload = (payload) => {
4023
+ try {
4024
+ if (this.#workersEx[payload.workerId]) {
4025
+ const runnersEx = this.#workersEx[payload.workerId].runnersEx;
4026
+ if (runnersEx) {
4027
+ payload.runners.forEach((runner) => {
4028
+ if (runnersEx[runner.id]) {
4029
+ this.#SyncRunnerData(runnersEx[runner.id], runner);
4030
+ }
4031
+ });
4199
4032
  }
4200
4033
  }
4201
- messageRecord.resolveMessage(retPayload);
4034
+ } catch (error) {
4035
+ this.#error(`#SyncWorkerDataFromPayload(): Error: [${error}]`);
4202
4036
  }
4203
- } catch (error) {
4204
- __privateGet(this, _error2).call(this, `#ProcessRunnerResponse(): Error: [${error}]`);
4205
- }
4206
- };
4207
- _SyncRunnerData = new WeakMap();
4208
- _SyncWorkerDataFromPayload = new WeakMap();
4209
- _SyncWorkerDataFromWorker = new WeakMap();
4210
- _SyncWorkerDataFromWorkers = new WeakMap();
4211
- _SetupCallbackMessage = new WeakMap();
4212
- _PostMessageToWorkerGetRunners = new WeakMap();
4037
+ };
4038
+ #SyncWorkerDataFromWorker = async (workerEx) => {
4039
+ try {
4040
+ const retVal = await this.#PostMessageToWorkerGetRunners(workerEx, eIWMessageCommands.GetRunners);
4041
+ this.#SyncWorkerDataFromPayload(retVal.payload);
4042
+ return retVal;
4043
+ } catch (error) {
4044
+ this.#error(`#SyncWorkerDataFromWorker(): Error: [${error}]`);
4045
+ throw error;
4046
+ }
4047
+ };
4048
+ #SyncWorkerDataFromWorkers = async () => {
4049
+ try {
4050
+ const retVal = await Promise.all(Object.values(this.#workersEx).map((workerEx) => this.#PostMessageToWorkerGetRunners(workerEx, eIWMessageCommands.GetRunners)));
4051
+ retVal.forEach((messagePayload) => {
4052
+ this.#SyncWorkerDataFromPayload(messagePayload.payload);
4053
+ });
4054
+ return retVal;
4055
+ } catch (error) {
4056
+ this.#error(`#SyncWorkerDataFromWorkers(): Error: [${error}]`);
4057
+ throw error;
4058
+ }
4059
+ };
4060
+ #SetupCallbackMessage = (resolve, reject, command) => {
4061
+ const messageId = v4();
4062
+ this.#messages[messageId] = {
4063
+ timeout: setTimeout(() => {
4064
+ delete this.#messages[messageId];
4065
+ reject(`STSWorkerManager:#SetupCallbackMessage(): message response timeout for message id: [${messageId}], command: [${command}]`);
4066
+ }, this.#options.messageTimeout),
4067
+ resolveMessage: (payload) => {
4068
+ resolve(payload);
4069
+ }
4070
+ };
4071
+ return messageId;
4072
+ };
4073
+ #PostMessageToWorkerGetRunners = async (workerEx, command) => {
4074
+ return new Promise((resolve, reject) => {
4075
+ try {
4076
+ const messageId = v4();
4077
+ this.#messages[messageId] = {
4078
+ timeout: setTimeout(() => {
4079
+ delete this.#messages[messageId];
4080
+ reject(`STSWorkerManager:#PostMessageToWorkerGetRunners(): message response timeout for message id: [${messageId}], command: [${command}]`);
4081
+ }, this.#options.messageTimeout),
4082
+ resolveMessage: (payload2) => {
4083
+ resolve(payload2);
4084
+ }
4085
+ };
4086
+ const payload = {
4087
+ messageId
4088
+ };
4089
+ workerEx.messagePort.postMessage({ command, payload });
4090
+ } catch (error) {
4091
+ this.#error(`#PostMessageToWorkerGetRunners(): Error: [${error}]`);
4092
+ }
4093
+ });
4094
+ };
4095
+ }
4213
4096
  exports2.IRunnerSignalType = IRunnerSignalType;
4214
4097
  exports2.IRunnerState = IRunnerState;
4215
4098
  exports2.IWorkerState = IWorkerState;
@@ -4218,5 +4101,5 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
4218
4101
  exports2.WorkerInstance = WorkerInstance;
4219
4102
  exports2.eIWMessageCommands = eIWMessageCommands;
4220
4103
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
4221
- });
4104
+ }));
4222
4105
  //# sourceMappingURL=stsrunnerframework.umd.js.map