@nsshunt/stsappframework 3.0.104 → 3.0.105
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/authutilsnode.js +6 -7
- package/dist/authutilsnode.js.map +1 -1
- package/dist/influxdb/influxDBManager.js +16 -17
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +9 -13
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +2 -6
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +10 -14
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/instrumentationsubscriber.js +11 -15
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +2 -6
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafkatesting/produce.js +1 -5
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/masterprocessbase.js +19 -20
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/processbase.js +7 -8
- package/dist/processbase.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/singleprocessbase.js +3 -4
- package/dist/singleprocessbase.js.map +1 -1
- package/dist/tcpclient/app2.js +2 -2
- package/dist/tcpserver/appmaster.js +39 -16
- package/dist/tcpserver/appmaster.js.map +1 -1
- package/dist/workerprocessbase.js +3 -4
- package/dist/workerprocessbase.js.map +1 -1
- package/package.json +7 -7
- package/src/authutilsnode.ts +8 -10
- package/src/influxdb/influxDBManager.ts +16 -18
- package/src/influxdb/influxDBManagerAgent.ts +9 -11
- package/src/influxdb/influxDBManagerBase.ts +2 -4
- package/src/influxdb/influxDBManagerService.ts +10 -12
- package/src/instrumentationsubscriber.ts +11 -14
- package/src/kafka/IMKafkaManager.ts +2 -4
- package/src/kafkatesting/produce.ts +1 -3
- package/src/masterprocessbase.ts +32 -24
- package/src/processbase.ts +7 -9
- package/src/server.ts +1 -1
- package/src/singleprocessbase.ts +3 -5
- package/src/tcpclient/app2.ts +2 -2
- package/src/tcpserver/appmaster.ts +39 -17
- package/src/workerprocessbase.ts +3 -5
- package/types/authutilsnode.d.ts.map +1 -1
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/processbase.d.ts +2 -2
- package/types/processbase.d.ts.map +1 -1
- package/types/singleprocessbase.d.ts.map +1 -1
- package/types/tcpserver/appmaster.d.ts.map +1 -1
- package/types/workerprocessbase.d.ts.map +1 -1
- package/src_working/authDefs.ts +0 -37
- package/src_working/authutilsnode.ts +0 -373
- package/src_working/commonTypes.ts +0 -239
- package/src_working/index.ts +0 -22
- package/src_working/influxdb/influxDBManager.ts +0 -970
- package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
- package/src_working/influxdb/influxDBManagerBase.ts +0 -109
- package/src_working/influxdb/influxDBManagerService.ts +0 -373
- package/src_working/instrumentationsubscriber.ts +0 -283
- package/src_working/kafka/IMKafkaManager.ts +0 -152
- package/src_working/kafka/kafkaconsumer.ts +0 -82
- package/src_working/kafka/kafkamanager.ts +0 -186
- package/src_working/kafka/kafkaproducer.ts +0 -58
- package/src_working/kafkatesting/config.ts +0 -10
- package/src_working/kafkatesting/consume.ts +0 -116
- package/src_working/kafkatesting/produce.ts +0 -153
- package/src_working/masterprocessbase.ts +0 -598
- package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working/network.ts +0 -36
- package/src_working/processbase.ts +0 -411
- package/src_working/processoptions.ts +0 -164
- package/src_working/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working/server.ts +0 -141
- package/src_working/serverprocessbase.ts +0 -393
- package/src_working/singleprocessbase.ts +0 -121
- package/src_working/socketIoServerHelper.ts +0 -177
- package/src_working/stscontrollerbase.ts +0 -15
- package/src_working/stslatencycontroller.ts +0 -27
- package/src_working/stslatencyroute.ts +0 -16
- package/src_working/stsrouterbase.ts +0 -22
- package/src_working/tcpclient/app.ts +0 -19
- package/src_working/tcpclient/app2.ts +0 -56
- package/src_working/tcpserver/app.ts +0 -11
- package/src_working/tcpserver/appConfig.ts +0 -65
- package/src_working/tcpserver/appmaster.ts +0 -544
- package/src_working/validation/errors.ts +0 -6
- package/src_working/webworkertesting/app.ts +0 -49
- package/src_working/webworkertesting/worker.ts +0 -24
- package/src_working/workerprocessbase.test.ts +0 -47
- package/src_working/workerprocessbase.ts +0 -185
- package/src_working2/authDefs.ts +0 -37
- package/src_working2/authutilsnode.ts +0 -375
- package/src_working2/commonTypes.ts +0 -239
- package/src_working2/index.ts +0 -22
- package/src_working2/influxdb/influxDBManager.ts +0 -972
- package/src_working2/influxdb/influxDBManagerAgent.ts +0 -316
- package/src_working2/influxdb/influxDBManagerBase.ts +0 -111
- package/src_working2/influxdb/influxDBManagerService.ts +0 -375
- package/src_working2/instrumentationsubscriber.ts +0 -286
- package/src_working2/kafka/IMKafkaManager.ts +0 -154
- package/src_working2/kafka/kafkaconsumer.ts +0 -82
- package/src_working2/kafka/kafkamanager.ts +0 -186
- package/src_working2/kafka/kafkaproducer.ts +0 -58
- package/src_working2/kafkatesting/config.ts +0 -10
- package/src_working2/kafkatesting/consume.ts +0 -116
- package/src_working2/kafkatesting/produce.ts +0 -155
- package/src_working2/masterprocessbase.ts +0 -590
- package/src_working2/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working2/network.ts +0 -36
- package/src_working2/processbase.ts +0 -415
- package/src_working2/processoptions.ts +0 -164
- package/src_working2/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working2/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working2/server.ts +0 -141
- package/src_working2/serverprocessbase.ts +0 -393
- package/src_working2/singleprocessbase.ts +0 -123
- package/src_working2/socketIoServerHelper.ts +0 -177
- package/src_working2/stscontrollerbase.ts +0 -15
- package/src_working2/stslatencycontroller.ts +0 -27
- package/src_working2/stslatencyroute.ts +0 -16
- package/src_working2/stsrouterbase.ts +0 -22
- package/src_working2/tcpclient/app.ts +0 -19
- package/src_working2/tcpclient/app2.ts +0 -56
- package/src_working2/tcpserver/app.ts +0 -11
- package/src_working2/tcpserver/appConfig.ts +0 -65
- package/src_working2/tcpserver/appmaster.ts +0 -522
- package/src_working2/validation/errors.ts +0 -6
- package/src_working2/webworkertesting/app.ts +0 -49
- package/src_working2/webworkertesting/worker.ts +0 -24
- package/src_working2/workerprocessbase.test.ts +0 -47
- 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
|
-
}
|