@nsshunt/stsrunnerframework 1.0.174 → 1.0.175

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