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