@nsshunt/stsrunnerframework 1.0.103 → 1.0.104

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.
@@ -1772,6 +1772,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1772
1772
  };
1773
1773
  __privateGet(this, _collectorCollectorPort).postMessage(message);
1774
1774
  await stsutils.Sleep(0);
1775
+ } else {
1776
+ __privateGet(this, _warn).call(this, `#PostMessageToWorkerManagerById(): Runner: [${runnerId}] not found`);
1775
1777
  }
1776
1778
  }
1777
1779
  } catch (error) {
@@ -1800,54 +1802,61 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1800
1802
  var _a;
1801
1803
  try {
1802
1804
  const runnerId = testRunnerTelemetryPayload.runner.id;
1803
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} StartRunner`);
1804
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.StartRunner());
1805
- __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.running);
1806
- const startLoop = /* @__PURE__ */ new Date();
1807
- const ExecuteLoop = async () => {
1808
- var _a2, _b;
1809
- try {
1810
- let cont = true;
1811
- const executionProfile = __privateGet(this, _GetRunnerExecutionProfileById).call(this, runnerId);
1812
- if (executionProfile) {
1813
- const { iterations, duration, delayBetweenIterations } = executionProfile;
1814
- if (iterations > 0) {
1815
- cont = __privateGet(this, _GetRunnerIterationById).call(this, runnerId) < iterations;
1816
- } else if (duration > 0) {
1817
- cont = ((/* @__PURE__ */ new Date()).getTime() - startLoop.getTime()) / 1e3 < duration;
1818
- }
1819
- if (cont) {
1820
- if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1821
- await ((_a2 = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a2.Execute());
1822
- if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1823
- __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
1805
+ if (__privateGet(this, _runners)[runnerId]) {
1806
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1807
+ if (state === IRunnerState.created) {
1808
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.StartRunner());
1809
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.running);
1810
+ await stsutils.Sleep(0);
1811
+ const startLoop = /* @__PURE__ */ new Date();
1812
+ const ExecuteLoop = async () => {
1813
+ var _a2, _b;
1814
+ try {
1815
+ let cont = true;
1816
+ const executionProfile = __privateGet(this, _GetRunnerExecutionProfileById).call(this, runnerId);
1817
+ if (executionProfile) {
1818
+ const { iterations, duration, delayBetweenIterations } = executionProfile;
1819
+ if (iterations > 0) {
1820
+ cont = __privateGet(this, _GetRunnerIterationById).call(this, runnerId) < iterations;
1821
+ } else if (duration > 0) {
1822
+ cont = ((/* @__PURE__ */ new Date()).getTime() - startLoop.getTime()) / 1e3 < duration;
1824
1823
  }
1825
- }
1826
- if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1827
- if (delayBetweenIterations > 0) {
1828
- await stsutils.Sleep(delayBetweenIterations);
1824
+ if (cont) {
1825
+ if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1826
+ await ((_a2 = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a2.Execute());
1827
+ if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1828
+ __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
1829
+ }
1830
+ }
1831
+ if (__privateGet(this, _CanExecuteNextIterationById).call(this, runnerId)) {
1832
+ if (delayBetweenIterations > 0) {
1833
+ await stsutils.Sleep(delayBetweenIterations);
1834
+ } else {
1835
+ await __privateMethod(this, _WorkerInstance_instances, SleepImmediate_fn).call(this);
1836
+ }
1837
+ ExecuteLoop();
1838
+ } else {
1839
+ if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1840
+ await stsutils.Sleep(50);
1841
+ ExecuteLoop();
1842
+ }
1843
+ }
1829
1844
  } else {
1830
- await __privateMethod(this, _WorkerInstance_instances, SleepImmediate_fn).call(this);
1845
+ await ((_b = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _b.Completed());
1846
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.completed);
1831
1847
  }
1832
- ExecuteLoop();
1833
1848
  } else {
1834
- if (!__privateGet(this, _IsCompletedById).call(this, runnerId)) {
1835
- await stsutils.Sleep(50);
1836
- ExecuteLoop();
1837
- }
1849
+ __privateGet(this, _warn).call(this, `#StartRunner:ExecuteLoop(): Cannot get execution profile for runner: [${runnerId}]`);
1838
1850
  }
1839
- } else {
1840
- await ((_b = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _b.Completed());
1841
- __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.completed);
1851
+ } catch (error) {
1852
+ __privateGet(this, _error).call(this, `#StartRunner:ExecuteLoop(): Error: [${error}]`);
1842
1853
  }
1843
- } else {
1844
- __privateGet(this, _warn).call(this, `#StartRunner:ExecuteLoop(): Cannot get execution profile for runner: [${runnerId}]`);
1845
- }
1846
- } catch (error) {
1847
- __privateGet(this, _error).call(this, `#StartRunner:ExecuteLoop(): Error: [${error}]`);
1854
+ };
1855
+ ExecuteLoop();
1848
1856
  }
1849
- };
1850
- ExecuteLoop();
1857
+ } else {
1858
+ __privateGet(this, _warn).call(this, `#StartRunner(): Runner: [${runnerId}] not found`);
1859
+ }
1851
1860
  } catch (error) {
1852
1861
  __privateGet(this, _error).call(this, `#StartRunner(): Error: [${error}]`);
1853
1862
  }
@@ -1855,22 +1864,26 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1855
1864
  __privateAdd(this, _StopRunnerByRunnerId, async (id) => {
1856
1865
  var _a;
1857
1866
  try {
1858
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${id}]`)} StopRunner`);
1859
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, id)) == null ? void 0 : _a.StopRunner());
1860
- await __privateGet(this, _UpdateRunnerStateById).call(this, id, IRunnerState.stopped);
1867
+ if (__privateGet(this, _runners)[id]) {
1868
+ const { state } = __privateGet(this, _runners)[id].runner;
1869
+ if (state === IRunnerState.paused || state === IRunnerState.running) {
1870
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, id)) == null ? void 0 : _a.StopRunner());
1871
+ __privateGet(this, _UpdateRunnerStateById).call(this, id, IRunnerState.stopped);
1872
+ }
1873
+ } else {
1874
+ __privateGet(this, _warn).call(this, `#StopRunnerByRunnerId(): Runner: [${id}] not found`);
1875
+ }
1861
1876
  } catch (error) {
1862
1877
  __privateGet(this, _error).call(this, `#StopRunnerByRunnerId(): Error: [${error}]`);
1863
1878
  }
1864
1879
  });
1865
1880
  __privateAdd(this, _StopAllRunners, async (testRunnerTelemetryPayload) => {
1866
1881
  try {
1867
- __privateGet(this, _debug).call(this, `StopAllRunners`);
1868
1882
  const promArray = [];
1869
1883
  for (const [, runner] of Object.entries(__privateGet(this, _GetAllRunners))) {
1870
1884
  promArray.push(__privateGet(this, _StopRunnerByRunnerId).call(this, runner.id));
1871
1885
  }
1872
1886
  await Promise.all(promArray);
1873
- await stsutils.Sleep(0);
1874
1887
  } catch (error) {
1875
1888
  __privateGet(this, _error).call(this, `#StopAllRunners(): Error: [${error}]`);
1876
1889
  }
@@ -1886,10 +1899,15 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1886
1899
  var _a;
1887
1900
  try {
1888
1901
  const runnerId = testRunnerTelemetryPayload.runner.id;
1889
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} TerminateRunner`);
1890
- const retVal = await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.TerminateRunner());
1891
- await __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.terminated);
1892
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} TerminateRunner Result = [${retVal}]`);
1902
+ if (__privateGet(this, _runners)[runnerId]) {
1903
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1904
+ if (state === IRunnerState.created || state === IRunnerState.paused || state === IRunnerState.running) {
1905
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.TerminateRunner());
1906
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.terminated);
1907
+ }
1908
+ } else {
1909
+ __privateGet(this, _warn).call(this, `#TerminateRunner(): Runner: [${runnerId}] not found`);
1910
+ }
1893
1911
  } catch (error) {
1894
1912
  __privateGet(this, _error).call(this, `#TerminateRunner(): Error: [${error}]`);
1895
1913
  }
@@ -1898,9 +1916,15 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1898
1916
  var _a;
1899
1917
  try {
1900
1918
  const runnerId = testRunnerTelemetryPayload.runner.id;
1901
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} PauseRunner`);
1902
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.PauseRunner());
1903
- await __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1919
+ if (__privateGet(this, _runners)[runnerId]) {
1920
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1921
+ if (state === IRunnerState.running) {
1922
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.PauseRunner());
1923
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1924
+ }
1925
+ } else {
1926
+ __privateGet(this, _warn).call(this, `#PauseRunner(): Runner: [${runnerId}] not found`);
1927
+ }
1904
1928
  } catch (error) {
1905
1929
  __privateGet(this, _error).call(this, `#PauseRunner(): Error: [${error}]`);
1906
1930
  }
@@ -1909,9 +1933,15 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1909
1933
  var _a;
1910
1934
  try {
1911
1935
  const runnerId = testRunnerTelemetryPayload.runner.id;
1912
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} ResumeRunner`);
1913
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResumeRunner());
1914
- await __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.running);
1936
+ if (__privateGet(this, _runners)[runnerId]) {
1937
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1938
+ if (state === IRunnerState.paused) {
1939
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResumeRunner());
1940
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.running);
1941
+ }
1942
+ } else {
1943
+ __privateGet(this, _warn).call(this, `#ResumeRunner(): Runner: [${runnerId}] not found`);
1944
+ }
1915
1945
  } catch (error) {
1916
1946
  __privateGet(this, _error).call(this, `#ResumeRunner(): Error: [${error}]`);
1917
1947
  }
@@ -1920,10 +1950,16 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1920
1950
  var _a;
1921
1951
  try {
1922
1952
  const runnerId = testRunnerTelemetryPayload.runner.id;
1923
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} ResetRunner`);
1924
- __privateGet(this, _ResetRunnerIterationById).call(this, runnerId);
1925
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResetRunner());
1926
- await __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1953
+ if (__privateGet(this, _runners)[runnerId]) {
1954
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1955
+ if (state === IRunnerState.paused || state === IRunnerState.running) {
1956
+ __privateGet(this, _ResetRunnerIterationById).call(this, runnerId);
1957
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.ResetRunner());
1958
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1959
+ }
1960
+ } else {
1961
+ __privateGet(this, _warn).call(this, `#ResetRunner(): Runner: [${runnerId}] not found`);
1962
+ }
1927
1963
  } catch (error) {
1928
1964
  __privateGet(this, _error).call(this, `#ResetRunner(): Error: [${error}]`);
1929
1965
  }
@@ -1933,12 +1969,19 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1933
1969
  var _a;
1934
1970
  try {
1935
1971
  const runnerId = testRunnerTelemetryPayload.runner.id;
1936
- const currentIteration = __privateGet(this, _GetRunnerIterationById).call(this, runnerId);
1937
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} ExecuteRunner(${currentIteration})`);
1938
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.Execute());
1939
- const newIteration = __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
1940
- __privateGet(this, _debug).call(this, `${chalk.magenta(` --> runner: [${runnerId}]`)} Next iteration number: [${newIteration}] for next Execute or Resume.`);
1941
- await __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1972
+ if (__privateGet(this, _runners)[runnerId]) {
1973
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1974
+ if (state === IRunnerState.paused || state === IRunnerState.created) {
1975
+ const currentIteration = __privateGet(this, _GetRunnerIterationById).call(this, runnerId);
1976
+ __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} ExecuteRunner(${currentIteration})`);
1977
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.Execute());
1978
+ const newIteration = __privateGet(this, _IncRunnerIterationById).call(this, runnerId);
1979
+ __privateGet(this, _debug).call(this, `${chalk.magenta(` --> runner: [${runnerId}]`)} Next iteration number: [${newIteration}] for next Execute or Resume.`);
1980
+ __privateGet(this, _UpdateRunnerStateById).call(this, runnerId, IRunnerState.paused);
1981
+ }
1982
+ } else {
1983
+ __privateGet(this, _warn).call(this, `#ExecuteRunner(): Runner: [${runnerId}] not found`);
1984
+ }
1942
1985
  } catch (error) {
1943
1986
  __privateGet(this, _error).call(this, `#ExecuteRunner(): Error: [${error}]`);
1944
1987
  }
@@ -1947,12 +1990,17 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1947
1990
  var _a;
1948
1991
  try {
1949
1992
  const runnerId = testRunnerTelemetryPayload.runner.id;
1950
- __privateGet(this, _debug).call(this, `${chalk.magenta(`runner: [${runnerId}]`)} UpdateOptions`);
1951
- __privateGet(this, _debug).call(this, chalk.cyan(`before: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
1952
- __privateGet(this, _SetRunnerOptionsById).call(this, runnerId, testRunnerTelemetryPayload.runner.options);
1953
- __privateGet(this, _debug).call(this, chalk.cyan(`after: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
1954
- await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.UpdateOptions());
1955
- await stsutils.Sleep(0);
1993
+ if (__privateGet(this, _runners)[runnerId]) {
1994
+ const { state } = __privateGet(this, _runners)[runnerId].runner;
1995
+ if (state === IRunnerState.paused || state === IRunnerState.created || state === IRunnerState.running) {
1996
+ __privateGet(this, _debug).call(this, chalk.cyan(`before: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
1997
+ __privateGet(this, _SetRunnerOptionsById).call(this, runnerId, testRunnerTelemetryPayload.runner.options);
1998
+ __privateGet(this, _debug).call(this, chalk.cyan(`after: [${JSON.stringify(__privateGet(this, _GetRunnerOptionsById).call(this, runnerId))}]`));
1999
+ await ((_a = __privateGet(this, _GetRunnerInstanceById).call(this, runnerId)) == null ? void 0 : _a.UpdateOptions());
2000
+ }
2001
+ } else {
2002
+ __privateGet(this, _warn).call(this, `#UpdateOptions(): Runner: [${runnerId}] not found`);
2003
+ }
1956
2004
  } catch (error) {
1957
2005
  __privateGet(this, _error).call(this, `#UpdateOptions(): Error: [${error}]`);
1958
2006
  }