@nsshunt/stsrunnerframework 2.0.30 → 2.0.32

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.
package/dist/index.mjs CHANGED
@@ -63,6 +63,8 @@ var eIWMessageCommands = /* @__PURE__ */ function(eIWMessageCommands) {
63
63
  eIWMessageCommands["RunnerStateChange"] = "__STS__RunnerStateChange";
64
64
  eIWMessageCommands["GetRunners"] = "__STS__GetRunners";
65
65
  eIWMessageCommands["GetRunnersResponse"] = "__STS__GetRunnersResponse";
66
+ eIWMessageCommands["PostWorkerMessage"] = "__STS__PostWorkerMessage";
67
+ eIWMessageCommands["PostWorkerMessageResponse"] = "__STS__PostWorkerMessageResponse";
66
68
  return eIWMessageCommands;
67
69
  }({});
68
70
  var IRunnerState = /* @__PURE__ */ function(IRunnerState) {
@@ -1015,6 +1017,25 @@ var AbstractRunnerExecutionWorker = class {
1015
1017
  this.#error(`#PostRunnersToWorkerManager(): [${error}]`);
1016
1018
  }
1017
1019
  };
1020
+ #PostWorkerMessageToWorkerManager = async (messagePayload) => {
1021
+ try {
1022
+ if (this.#collectorCollectorPort) {
1023
+ const response = await this.ProcessGenericWorkerMessage(messagePayload);
1024
+ const message = {
1025
+ command: eIWMessageCommands.PostWorkerMessageResponse,
1026
+ payload: {
1027
+ messageId: messagePayload.payload.messageId,
1028
+ workerId: this.#workerId,
1029
+ response
1030
+ }
1031
+ };
1032
+ this.#collectorCollectorPort.postMessage(message);
1033
+ await Sleep(0);
1034
+ }
1035
+ } catch (error) {
1036
+ this.#error(`#PostWorkerMessageToWorkerManager(): [${error}]`);
1037
+ }
1038
+ };
1018
1039
  /**
1019
1040
  * Start a runner and, if valid, launch its execution loop.
1020
1041
  *
@@ -1395,6 +1416,9 @@ var AbstractRunnerExecutionWorker = class {
1395
1416
  }
1396
1417
  this.#SendRunnerCommandResponse(eIWMessageCommands.UpdateRunnerResponse, testRunnerTelemetryPayload, result);
1397
1418
  };
1419
+ async ProcessGenericWorkerMessage(messagePayload) {
1420
+ return {};
1421
+ }
1398
1422
  /**
1399
1423
  * Main inbound message dispatcher for this worker runtime.
1400
1424
  *
@@ -1474,6 +1498,10 @@ var AbstractRunnerExecutionWorker = class {
1474
1498
  this.#silly(`ProcessMessage::GetRunners`);
1475
1499
  this.#PostRunnersToWorkerManager(eIWMessageCommands.GetRunners, payloadMessage);
1476
1500
  break;
1501
+ case eIWMessageCommands.PostWorkerMessage:
1502
+ this.#silly(`ProcessMessage::PostWorkerMessage`);
1503
+ this.#PostWorkerMessageToWorkerManager(payloadMessage);
1504
+ break;
1477
1505
  default: this.#warn(`ProcessMessage::default: Invalid payloadMessage.command: [${payloadMessage.command}] - Ignoring`);
1478
1506
  }
1479
1507
  } catch (error) {
@@ -3234,10 +3262,11 @@ var STSMessageBroker = class {
3234
3262
  * @param command Worker-level command to send.
3235
3263
  * @returns Promise resolving with the response payload returned by the worker.
3236
3264
  */
3237
- SendMessageToWorkerForWorkerWithCallBack = async (workerEx, command) => {
3265
+ SendMessageToWorkerForWorkerWithCallBack = async (workerEx, command, data) => {
3238
3266
  return new Promise((resolve, reject) => {
3239
3267
  try {
3240
3268
  const payload = { messageId: this._SetupCallbackMessage(resolve, reject, command) };
3269
+ if (data !== void 0) payload.data = data;
3241
3270
  workerEx.messagePort.postMessage({
3242
3271
  command,
3243
3272
  payload
@@ -6630,6 +6659,27 @@ var STSWorkerManager = class {
6630
6659
  GetNextAvailableWorker = () => {
6631
6660
  return this.#workerRegistry.GetNextAvailableWorker();
6632
6661
  };
6662
+ PostWorkerMessage = async (workerIds, data) => {
6663
+ try {
6664
+ /**
6665
+ * Resolve all live workers.
6666
+ *
6667
+ * Passing `[]` means "all workers" according to the registry convention.
6668
+ */
6669
+ const workersEx = this.#workerRegistry.GetWorkersEx(workerIds);
6670
+ /**
6671
+ * Build a broker request promise for each worker.
6672
+ *
6673
+ * Each worker is asked to return its full current runner list.
6674
+ */
6675
+ const promArray = [];
6676
+ workersEx.forEach((workerEx) => promArray.push(this.#messageBroker.SendMessageToWorkerForWorkerWithCallBack(workerEx, eIWMessageCommands.PostWorkerMessage, data)));
6677
+ return await Promise.all(promArray);
6678
+ } catch (error) {
6679
+ this.options.logger.error(`_SyncWorkerDataFromWorkers(): Error: [${error}]`);
6680
+ throw error;
6681
+ }
6682
+ };
6633
6683
  };
6634
6684
  //#endregion
6635
6685
  //#region node_modules/@nsshunt/stssocketioutils/dist/tiny-emitter-DcZ69ZvJ.js
@@ -9974,6 +10024,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
9974
10024
  #socket;
9975
10025
  #reconnectTimeout = 2e3;
9976
10026
  #ackTimeout = 5e3;
10027
+ #reconnectTimeoutVal = void 0;
9977
10028
  constructor(name) {
9978
10029
  super();
9979
10030
  this.#name = name;
@@ -10046,7 +10097,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10046
10097
  return this;
10047
10098
  }
10048
10099
  SetupSocket() {
10049
- if (!this.#address) throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
10100
+ if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
10050
10101
  this.#EstablishSocketConnect();
10051
10102
  return this;
10052
10103
  }
@@ -10056,17 +10107,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10056
10107
  EngineReconnect(attempt) {}
10057
10108
  #EstablishSocketConnect() {
10058
10109
  if (this.#socket !== void 0) {
10059
- if (this.#socket.connected === true) this.#socket.disconnect();
10060
- this.#socket = void 0;
10061
- if (isNode) setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10062
- else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10110
+ this.ResetSocket();
10111
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10112
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10063
10113
  return;
10064
10114
  }
10065
10115
  let socketOptions;
10066
10116
  if (isNode) {
10067
10117
  socketOptions = { transports: ["websocket"] };
10068
10118
  if (this.#agentManager) {
10069
- if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
10119
+ if (!this.#address) {
10120
+ const message = `SocketIoClient:#EstablishSocketConnect(): Error: [address not provided when using agentManager]`;
10121
+ this.LogErrorMessage(message);
10122
+ throw new Error(message);
10123
+ }
10070
10124
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
10071
10125
  }
10072
10126
  } else socketOptions = { transports: ["websocket"] };
@@ -10077,30 +10131,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10077
10131
  if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
10078
10132
  this.#socket = lookup(this.#address, socketOptions);
10079
10133
  this.#socket.io.on("error", (err) => {
10080
- this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10134
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10081
10135
  this.EngineError(err);
10082
10136
  });
10083
10137
  this.#socket.io.on("reconnect_error", (err) => {
10084
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10138
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10085
10139
  this.EngineReconnectError(err);
10086
10140
  });
10087
10141
  this.#socket.on("connect_error", (err) => {
10088
- this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10142
+ this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10089
10143
  this.EngineConnectError(err);
10090
10144
  });
10091
10145
  this.#socket.io.on("reconnect", (attempt) => {
10092
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10146
+ this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10093
10147
  this.EngineReconnect(attempt);
10094
10148
  });
10095
10149
  this.#socket.on("connect", () => {
10096
10150
  if (this.#socket) {
10097
- this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10151
+ this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10098
10152
  setTimeout(() => {
10099
10153
  this.SocketConnect(this.#socket);
10100
10154
  }, 0);
10101
10155
  this.SetupSocketEvents(this.#socket);
10102
10156
  } else {
10103
- const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10157
+ const errorMessage = "SocketIoClient:on(\"connect\"): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10104
10158
  this.LogErrorMessage(errorMessage);
10105
10159
  this.SocketConnectError(new Error(errorMessage));
10106
10160
  }
@@ -10110,33 +10164,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10110
10164
  this.SocketDisconnect(reason);
10111
10165
  switch (reason) {
10112
10166
  case "io server disconnect":
10113
- this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10114
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10115
- this.#socket = void 0;
10116
- if (isNode) {
10117
- if (this.#agentManager) this.#agentManager.ResetAgent();
10118
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10119
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10167
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10168
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10169
+ this.ResetSocket();
10170
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10171
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10120
10172
  break;
10121
10173
  case "io client disconnect":
10122
- this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10123
- this.LogDebugMessage("The connection will not be re-established automatically.");
10174
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10175
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will not be re-established automatically.");
10176
+ this.ResetSocket();
10124
10177
  break;
10125
10178
  case "transport close":
10126
10179
  case "ping timeout":
10127
10180
  case "transport error":
10128
- this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
10129
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10130
- if (this.#socket) this.#socket.disconnect();
10131
- this.#socket = void 0;
10132
- if (isNode) {
10133
- if (this.#agentManager) this.#agentManager?.ResetAgent();
10134
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10135
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10181
+ this.LogDebugMessage(`SocketIoClient:on("disconnect"): Server unexpectedly disconnected. Reason: [${reason}]`);
10182
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10183
+ this.ResetSocket();
10184
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10185
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10136
10186
  break;
10137
10187
  }
10138
10188
  });
10139
10189
  }
10190
+ ResetSocket = () => {
10191
+ try {
10192
+ if (this.#reconnectTimeoutVal !== void 0) {
10193
+ clearTimeout(this.#reconnectTimeoutVal);
10194
+ this.#reconnectTimeoutVal = void 0;
10195
+ }
10196
+ if (this.#socket) {
10197
+ this.#socket.removeAllListeners();
10198
+ this.#socket.io.removeAllListeners();
10199
+ if (this.#socket.connected === true) this.#socket.disconnect();
10200
+ if (isNode) {
10201
+ if (this.#agentManager) this.#agentManager.ResetAgent();
10202
+ }
10203
+ this.#socket = void 0;
10204
+ }
10205
+ } catch (error) {
10206
+ const errorMessage = `SocketIoClient:ResetSocket(): Error: [${error}]`;
10207
+ this.LogErrorMessage(errorMessage);
10208
+ this.SocketConnectError(new Error(errorMessage));
10209
+ }
10210
+ };
10140
10211
  };
10141
10212
  //#endregion
10142
10213
  //#region src/wsevents.ts