@nsshunt/stsappframework 3.0.104 → 3.0.106

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.
Files changed (124) hide show
  1. package/dist/influxdb/influxDBManager.js +16 -17
  2. package/dist/influxdb/influxDBManager.js.map +1 -1
  3. package/dist/influxdb/influxDBManagerAgent.js +9 -13
  4. package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
  5. package/dist/influxdb/influxDBManagerBase.js +2 -6
  6. package/dist/influxdb/influxDBManagerBase.js.map +1 -1
  7. package/dist/influxdb/influxDBManagerService.js +10 -14
  8. package/dist/influxdb/influxDBManagerService.js.map +1 -1
  9. package/dist/instrumentationsubscriber.js +11 -15
  10. package/dist/instrumentationsubscriber.js.map +1 -1
  11. package/dist/kafka/IMKafkaManager.js +2 -6
  12. package/dist/kafka/IMKafkaManager.js.map +1 -1
  13. package/dist/kafkatesting/produce.js +1 -5
  14. package/dist/kafkatesting/produce.js.map +1 -1
  15. package/dist/processbase.js +7 -8
  16. package/dist/processbase.js.map +1 -1
  17. package/dist/server.js +1 -1
  18. package/dist/server.js.map +1 -1
  19. package/dist/tcpclient/app2.js +2 -2
  20. package/dist/tcpserver/appmaster.js +39 -16
  21. package/dist/tcpserver/appmaster.js.map +1 -1
  22. package/package.json +7 -7
  23. package/src/influxdb/influxDBManager.ts +16 -18
  24. package/src/influxdb/influxDBManagerAgent.ts +9 -11
  25. package/src/influxdb/influxDBManagerBase.ts +2 -4
  26. package/src/influxdb/influxDBManagerService.ts +10 -12
  27. package/src/instrumentationsubscriber.ts +11 -14
  28. package/src/kafka/IMKafkaManager.ts +2 -4
  29. package/src/kafkatesting/produce.ts +1 -3
  30. package/src/processbase.ts +7 -9
  31. package/src/server.ts +1 -1
  32. package/src/tcpclient/app2.ts +2 -2
  33. package/src/tcpserver/appmaster.ts +39 -17
  34. package/types/influxdb/influxDBManager.d.ts.map +1 -1
  35. package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
  36. package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
  37. package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
  38. package/types/instrumentationsubscriber.d.ts.map +1 -1
  39. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  40. package/types/processbase.d.ts +2 -2
  41. package/types/processbase.d.ts.map +1 -1
  42. package/types/tcpserver/appmaster.d.ts.map +1 -1
  43. package/src_working/authDefs.ts +0 -37
  44. package/src_working/authutilsnode.ts +0 -373
  45. package/src_working/commonTypes.ts +0 -239
  46. package/src_working/index.ts +0 -22
  47. package/src_working/influxdb/influxDBManager.ts +0 -970
  48. package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
  49. package/src_working/influxdb/influxDBManagerBase.ts +0 -109
  50. package/src_working/influxdb/influxDBManagerService.ts +0 -373
  51. package/src_working/instrumentationsubscriber.ts +0 -283
  52. package/src_working/kafka/IMKafkaManager.ts +0 -152
  53. package/src_working/kafka/kafkaconsumer.ts +0 -82
  54. package/src_working/kafka/kafkamanager.ts +0 -186
  55. package/src_working/kafka/kafkaproducer.ts +0 -58
  56. package/src_working/kafkatesting/config.ts +0 -10
  57. package/src_working/kafkatesting/consume.ts +0 -116
  58. package/src_working/kafkatesting/produce.ts +0 -153
  59. package/src_working/masterprocessbase.ts +0 -598
  60. package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
  61. package/src_working/network.ts +0 -36
  62. package/src_working/processbase.ts +0 -411
  63. package/src_working/processoptions.ts +0 -164
  64. package/src_working/publishertransports/publishTransportDirect.ts +0 -45
  65. package/src_working/publishertransports/publishTransportUtils.ts +0 -53
  66. package/src_working/server.ts +0 -141
  67. package/src_working/serverprocessbase.ts +0 -393
  68. package/src_working/singleprocessbase.ts +0 -121
  69. package/src_working/socketIoServerHelper.ts +0 -177
  70. package/src_working/stscontrollerbase.ts +0 -15
  71. package/src_working/stslatencycontroller.ts +0 -27
  72. package/src_working/stslatencyroute.ts +0 -16
  73. package/src_working/stsrouterbase.ts +0 -22
  74. package/src_working/tcpclient/app.ts +0 -19
  75. package/src_working/tcpclient/app2.ts +0 -56
  76. package/src_working/tcpserver/app.ts +0 -11
  77. package/src_working/tcpserver/appConfig.ts +0 -65
  78. package/src_working/tcpserver/appmaster.ts +0 -544
  79. package/src_working/validation/errors.ts +0 -6
  80. package/src_working/webworkertesting/app.ts +0 -49
  81. package/src_working/webworkertesting/worker.ts +0 -24
  82. package/src_working/workerprocessbase.test.ts +0 -47
  83. package/src_working/workerprocessbase.ts +0 -185
  84. package/src_working2/authDefs.ts +0 -37
  85. package/src_working2/authutilsnode.ts +0 -375
  86. package/src_working2/commonTypes.ts +0 -239
  87. package/src_working2/index.ts +0 -22
  88. package/src_working2/influxdb/influxDBManager.ts +0 -972
  89. package/src_working2/influxdb/influxDBManagerAgent.ts +0 -316
  90. package/src_working2/influxdb/influxDBManagerBase.ts +0 -111
  91. package/src_working2/influxdb/influxDBManagerService.ts +0 -375
  92. package/src_working2/instrumentationsubscriber.ts +0 -286
  93. package/src_working2/kafka/IMKafkaManager.ts +0 -154
  94. package/src_working2/kafka/kafkaconsumer.ts +0 -82
  95. package/src_working2/kafka/kafkamanager.ts +0 -186
  96. package/src_working2/kafka/kafkaproducer.ts +0 -58
  97. package/src_working2/kafkatesting/config.ts +0 -10
  98. package/src_working2/kafkatesting/consume.ts +0 -116
  99. package/src_working2/kafkatesting/produce.ts +0 -155
  100. package/src_working2/masterprocessbase.ts +0 -590
  101. package/src_working2/middleware/serverNetworkMiddleware.ts +0 -240
  102. package/src_working2/network.ts +0 -36
  103. package/src_working2/processbase.ts +0 -415
  104. package/src_working2/processoptions.ts +0 -164
  105. package/src_working2/publishertransports/publishTransportDirect.ts +0 -45
  106. package/src_working2/publishertransports/publishTransportUtils.ts +0 -53
  107. package/src_working2/server.ts +0 -141
  108. package/src_working2/serverprocessbase.ts +0 -393
  109. package/src_working2/singleprocessbase.ts +0 -123
  110. package/src_working2/socketIoServerHelper.ts +0 -177
  111. package/src_working2/stscontrollerbase.ts +0 -15
  112. package/src_working2/stslatencycontroller.ts +0 -27
  113. package/src_working2/stslatencyroute.ts +0 -16
  114. package/src_working2/stsrouterbase.ts +0 -22
  115. package/src_working2/tcpclient/app.ts +0 -19
  116. package/src_working2/tcpclient/app2.ts +0 -56
  117. package/src_working2/tcpserver/app.ts +0 -11
  118. package/src_working2/tcpserver/appConfig.ts +0 -65
  119. package/src_working2/tcpserver/appmaster.ts +0 -522
  120. package/src_working2/validation/errors.ts +0 -6
  121. package/src_working2/webworkertesting/app.ts +0 -49
  122. package/src_working2/webworkertesting/worker.ts +0 -24
  123. package/src_working2/workerprocessbase.test.ts +0 -47
  124. package/src_working2/workerprocessbase.ts +0 -187
@@ -1,187 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import debugModule from 'debug'
3
- const debug = debugModule(`proc:${process.pid}`);
4
-
5
- import chalk from 'chalk';
6
-
7
- import { Gauge, InstrumentGaugeTelemetry } from '@nsshunt/stsinstrumentation'
8
- import { JSONObject } from '@nsshunt/stsutils'
9
- import { ProcessOptions } from './processoptions'
10
- import { IPCMessage, IPCMessages, IPCMessagePayload, IPCMessageCommand, IWorkerProcessBase } from './commonTypes'
11
- import { STSExpressServer } from './server';
12
- import { ServerProcessBase } from './serverprocessbase'
13
-
14
- import { v4 as uuidv4 } from 'uuid';
15
-
16
- import colors from 'colors'
17
-
18
- /**
19
- * todo
20
- * @typedef {Object} options - todo
21
- * @property {boolean} [wssServer=false] - Create a web socket server on this worker instance
22
- */
23
- export class WorkerProcessBase extends ServerProcessBase implements IWorkerProcessBase
24
- {
25
- #inFlightMessage: IPCMessages = { }
26
- #requestResponseMessageTimeout = 2000; //@@ config
27
-
28
- constructor(options: ProcessOptions) {
29
- super(options);
30
- }
31
-
32
- WorkerStarted() {
33
- return null;
34
- }
35
-
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
37
- ReceivedMessageFromMaster(msg: any) {
38
- // Override in subclass if required
39
- }
40
-
41
- override CollectAdditionalTelemetry(): void {
42
- this.httpServer.getConnections((error: any, count: any) => {
43
- //@@this.instruments[Gauge.CONNECTION_COUNT_GAUGE].val = count;
44
- this.UpdateInstrument(Gauge.CONNECTION_COUNT_GAUGE, {
45
- val: count
46
- } as InstrumentGaugeTelemetry);
47
- });
48
- }
49
-
50
- #SendMessageToParentProcess = (message: IPCMessagePayload): Promise<JSONObject> => {
51
- return new Promise((resolve, reject) => {
52
- if (this.#inFlightMessage[message.id]) {
53
- reject(`Message with id: [${message.id}] already exists within the Request/Response record structure`);
54
- } else {
55
- this.#inFlightMessage[message.id] = {
56
- iPCMessagePayload: { ...message },
57
- cb: () => {
58
- const detail: JSONObject = this.#inFlightMessage[message.id].iPCMessagePayload.responseDetail as JSONObject
59
- clearTimeout(this.#inFlightMessage[message.id].timeout);
60
- setTimeout(() => {
61
- delete this.#inFlightMessage[message.id];
62
- }, 0).unref();
63
- debug(chalk.green(`Resolving response message with id: [${message.id}] from parent process via IPC. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
64
- resolve(detail);
65
- },
66
- timeout: setTimeout(() => {
67
- setTimeout(() => {
68
- delete this.#inFlightMessage[message.id];
69
- }, 0).unref();
70
- debug(chalk.red(`Timeout has occurred after: [${this.#requestResponseMessageTimeout}]ms with message id: [${message.id}]. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
71
- reject('Did not receive response form parent process.');
72
- }, this.#requestResponseMessageTimeout) // max message timeout allowed
73
- }
74
- debug(`Sending message with id: [${message.id}] to parent process via IPC. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`.yellow);
75
- (process as any).send(message);
76
- }
77
- });
78
- }
79
-
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- AddWorker = async (options: any): Promise<string> => {
82
- const workerResponse: JSONObject = await this.#SendMessageToParentProcess({
83
- requestResponse: true,
84
- id: uuidv4(),
85
- command: IPCMessageCommand.AddWorker,
86
- requestDetail: {
87
- options
88
- }
89
- });
90
- return workerResponse.workerId;
91
- }
92
-
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- DeleteWorker = async (workerId: string, options: any): Promise<JSONObject> => {
95
- const workerResponse: JSONObject = await this.#SendMessageToParentProcess({
96
- requestResponse: true,
97
- id: uuidv4(),
98
- command: IPCMessageCommand.DeleteWorker,
99
- requestDetail: {
100
- options,
101
- workerId
102
- }
103
- });
104
- return workerResponse;
105
- }
106
-
107
- ProcessTerminating = async (): Promise<void> => {
108
- return;
109
- }
110
-
111
- SetupServer = async () =>
112
- {
113
- this.SetupInstrumentation();
114
- setTimeout(() => {
115
- this.SetupServerEx();
116
- }, 100);
117
- }
118
-
119
- SetupServerEx = async () => {
120
- this.ProcessStartup();
121
-
122
- if (this.options.expressServerRouteFactory || this.options.expressServerRouteStaticFactory) {
123
- this.expressServer = new STSExpressServer(this.options, this);
124
- }
125
-
126
- this.LogEx(`Worker instance starting. Service instance Id: [${this.options.serviceInstanceId}]`);
127
-
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- process.on('message', async (msg: any) => {
130
- if (msg.requestResponse) {
131
- const iPCMessagePayload: IPCMessagePayload = msg as IPCMessagePayload;
132
- if (iPCMessagePayload.id) {
133
- if (this.#inFlightMessage[iPCMessagePayload.id]) {
134
- const responseMessage: IPCMessage = this.#inFlightMessage[iPCMessagePayload.id];
135
- responseMessage.iPCMessagePayload.responseDetail = { ...iPCMessagePayload.responseDetail }
136
- responseMessage.cb();
137
- } else {
138
- throw new Error(`Could not find Request/Response message with id: [${iPCMessagePayload.id}]`);
139
- }
140
- } else {
141
- throw new Error(`Message does not have id attribute. [${JSON.stringify(iPCMessagePayload)}]`);
142
- }
143
- return;
144
- }
145
- if (msg.command) //@@ constants
146
- {
147
- switch (msg.command)
148
- {
149
- case 'Terminate' :
150
- this.LogEx((`Received ` + colors.bold(`Terminate`.italic) + ` message from master thread`).gray);
151
- await this.Terminate(true, false); // Don't kill the child process here, the master will take care of that ...
152
- break;
153
- case 'TerminateAndKill' :
154
- this.LogEx((`Received ` + colors.bold(`Terminate`.italic) + ` message from master thread`).gray);
155
- await this.Terminate(true, true);
156
- break;
157
- case 'Message' :
158
- //this.LogEx((`Received ` + colors.bold(`Message`.italic) + ` message from master thread`).gray);
159
- this.ReceivedMessageFromMaster(msg.data);
160
- break;
161
- case 'Response' : // General response to a req/response interaction
162
- msg.details
163
- }
164
- }
165
- });
166
-
167
- // Signal Codes
168
- // https://en.wikipedia.org/wiki/Signal_(IPC)
169
- process.on('SIGTERM', async () =>
170
- {
171
- this.LogEx(`SIGTERM signal received for worker: ${process.pid}`);
172
- await this.Terminate(true, true);
173
- });
174
-
175
- process.on('SIGINT', async () =>
176
- {
177
- this.LogEx(`SIGINT signal received for worker: ${process.pid}`);
178
- await this.Terminate(true, true);
179
- });
180
-
181
- await this.SetupSTSServer();
182
-
183
- this.WorkerStarted();
184
-
185
- this.LogEx(chalk.green(`Worker process:${process.pid} started`));
186
- };
187
- }