@nsshunt/stsappframework 3.1.131 → 3.1.133
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.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ipcMessageHandler.js +1 -1
- package/dist/ipcMessageManager.js +1 -24
- package/dist/ipcMessageManager.js.map +1 -1
- package/dist/ipcMessageProcessorPrimary.js +1 -1
- package/dist/masterprocessbase.js +15 -0
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/redisMessageHandler.js +57 -121
- package/dist/redisMessageHandler.js.map +1 -1
- package/dist/testing/app.js +61 -21
- package/dist/testing/app.js.map +1 -1
- package/dist/workerprocessbase.js +23 -13
- package/dist/workerprocessbase.js.map +1 -1
- package/package.json +1 -1
- package/runtest2.sh +1 -1
- package/src/index.ts +1 -0
- package/src/ipcMessageHandler.ts +1 -1
- package/src/ipcMessageManager.ts +1 -29
- package/src/ipcMessageProcessorPrimary.ts +1 -1
- package/src/masterprocessbase.ts +19 -1
- package/src/redisMessageHandler.ts +74 -129
- package/src/testing/app.ts +73 -25
- package/src/workerprocessbase.ts +22 -12
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/ipcMessageManager.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/redisMessageHandler.d.ts +16 -1
- package/types/redisMessageHandler.d.ts.map +1 -1
- package/types/workerprocessbase.d.ts +2 -1
- package/types/workerprocessbase.d.ts.map +1 -1
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { TinyEmitter } from "tiny-emitter";
|
|
3
3
|
import { ISTSLogger, JSONObject } from '@nsshunt/stsutils'
|
|
4
4
|
|
|
5
|
-
import { IIPCMessageProcessorIPCPayload } from './commonTypes'
|
|
5
|
+
import { IIPCMessageProcessorIPCPayload, IServiceProcessContext } from './commonTypes'
|
|
6
6
|
|
|
7
7
|
import { IPCMessageManager, IPCMessageManagerOptions } from './ipcMessageManager'
|
|
8
8
|
import { Redis, RedisOptions } from "ioredis";
|
|
9
9
|
|
|
10
10
|
import chalk from 'chalk';
|
|
11
|
+
import { AggregateSteps } from "redis";
|
|
12
|
+
import { ProcessOptions } from "./processoptions";
|
|
11
13
|
|
|
12
14
|
const REQUEST_CHANNEL = '__STS__SVC_stsappframework_request'
|
|
13
15
|
const RESPONSE_CHANNEL = '__STS__SVC_stsappframework_response'
|
|
@@ -18,6 +20,8 @@ export interface IRedisAdminManagerOptions {
|
|
|
18
20
|
role: 'SERVER' | 'CLIENT'
|
|
19
21
|
namespace: string
|
|
20
22
|
groups: string[]
|
|
23
|
+
ignoreEvents?: string[]
|
|
24
|
+
processOptions?: ProcessOptions
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export interface IClientRecord {
|
|
@@ -26,6 +30,7 @@ export interface IClientRecord {
|
|
|
26
30
|
pingCount: number
|
|
27
31
|
timeout: NodeJS.Timeout
|
|
28
32
|
groups: string[]
|
|
33
|
+
serviceProcessContext?: IServiceProcessContext
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export interface IEventPayload {
|
|
@@ -39,6 +44,12 @@ export interface IEventRecord {
|
|
|
39
44
|
ctx?: any
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
export interface IPingData {
|
|
48
|
+
id: string
|
|
49
|
+
groups: string[]
|
|
50
|
+
serviceProcessContext?: IServiceProcessContext
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
export class RedisMessageHandler extends TinyEmitter {
|
|
43
54
|
#ipcMessageManager: IPCMessageManager | null = null;
|
|
44
55
|
#options: IRedisAdminManagerOptions;
|
|
@@ -80,26 +91,21 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
80
91
|
if (this.#options.role.localeCompare('CLIENT') === 0) {
|
|
81
92
|
const ping = () => {
|
|
82
93
|
this.#pingTimeout = setTimeout(() => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
94
|
+
const pingData: IPingData = {
|
|
95
|
+
id: (this.#ipcMessageManager as IPCMessageManager).id,
|
|
96
|
+
groups: this.#options.groups,
|
|
97
|
+
}
|
|
98
|
+
if (this.#options.processOptions) {
|
|
99
|
+
pingData.serviceProcessContext = this.#options.processOptions.serviceProcessContext;
|
|
88
100
|
}
|
|
89
|
-
|
|
90
|
-
this.emit('ping', {
|
|
91
|
-
id: this.#ipcMessageManager?.id,
|
|
92
|
-
groups: [
|
|
93
|
-
group
|
|
94
|
-
]
|
|
95
|
-
}, (response: any) => { });
|
|
101
|
+
this.emit('ping', pingData, (response: any) => { });
|
|
96
102
|
ping();
|
|
97
103
|
}, 1000).unref();
|
|
98
104
|
}
|
|
99
105
|
ping();
|
|
100
106
|
} else {
|
|
101
|
-
this.on('ping', (pingData:
|
|
102
|
-
const { id, groups } = pingData;
|
|
107
|
+
this.on('ping', (pingData: IPingData, callback: any) => {
|
|
108
|
+
const { id, groups, serviceProcessContext } = pingData;
|
|
103
109
|
if (this.#clients[id]) {
|
|
104
110
|
clearTimeout(this.#clients[id].timeout);
|
|
105
111
|
this.#clients[id].pingCount++;
|
|
@@ -107,6 +113,7 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
107
113
|
delete this.#clients[id];
|
|
108
114
|
}, 2000);
|
|
109
115
|
this.#clients[id].groups = groups;
|
|
116
|
+
this.#clients[id].serviceProcessContext = serviceProcessContext;
|
|
110
117
|
} else {
|
|
111
118
|
this.#clients[id] = {
|
|
112
119
|
id,
|
|
@@ -115,16 +122,13 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
115
122
|
timeout: setTimeout(() => {
|
|
116
123
|
delete this.#clients[id];
|
|
117
124
|
}, 2000),
|
|
118
|
-
groups
|
|
125
|
+
groups,
|
|
126
|
+
serviceProcessContext
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
|
-
//console.log(chalk.gray(` ${process.pid}: processed ping ...`))
|
|
122
129
|
callback('ok');
|
|
123
130
|
});
|
|
124
131
|
}
|
|
125
|
-
|
|
126
|
-
console.log(chalk.yellow(`RedisMessageHandler:constructor(): [${JSON.stringify(this.#options.groups)}]`));
|
|
127
|
-
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
#LogInfo(message: any) {
|
|
@@ -140,10 +144,32 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
140
144
|
this.#ipcMessageManager?.ProcessMessage(message, { channel });
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
get clients(): Record<string, IClientRecord> {
|
|
148
|
+
return this.#clients;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get groups(): string[] {
|
|
152
|
+
return this.#options.groups;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
AddGroup = (group: string) => {
|
|
156
|
+
const index = this.#options.groups.indexOf(group);
|
|
157
|
+
if (index === -1) {
|
|
158
|
+
this.#options.groups.push(group);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
RemoveGroup = (group: string) => {
|
|
163
|
+
const removeIndex = this.#options.groups.indexOf(group);
|
|
164
|
+
if (removeIndex !== -1) {
|
|
165
|
+
this.#options.groups.splice(removeIndex, 1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
143
169
|
SetupPrimary = () => {
|
|
144
170
|
const ipcMessageManagerOptions: IPCMessageManagerOptions = {
|
|
145
171
|
logger: this.#options.logger,
|
|
146
|
-
requestResponseMessageTimeout:
|
|
172
|
+
requestResponseMessageTimeout: 5000,
|
|
147
173
|
namespace: this.#options.namespace,
|
|
148
174
|
role: this.#options.role,
|
|
149
175
|
messageSender: this.#messageSender,
|
|
@@ -179,48 +205,34 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
179
205
|
// Now check if we have all responses ...
|
|
180
206
|
let allFound = false;
|
|
181
207
|
|
|
182
|
-
Object.
|
|
183
|
-
if (
|
|
208
|
+
for (const [responseId, response] of Object.entries(responses)) {
|
|
209
|
+
if (response.senderRole.localeCompare('CLIENT') === 0) {
|
|
184
210
|
allFound = true;
|
|
211
|
+
break;
|
|
185
212
|
}
|
|
186
|
-
}
|
|
213
|
+
}
|
|
187
214
|
if (allFound) {
|
|
188
215
|
return allFound;
|
|
189
216
|
}
|
|
190
217
|
|
|
191
|
-
console.log(chalk.grey(`${process.pid}: -->> *** <<-- #ProcessResponseMessage`));
|
|
192
218
|
let found = true;
|
|
193
219
|
|
|
194
220
|
// Sender role here is SERVER
|
|
195
|
-
|
|
196
|
-
console.log(chalk.yellow(`${process.pid}: Total Clients :-`));
|
|
197
|
-
Object.values(this.#clients).forEach(c => {
|
|
198
|
-
console.log(chalk.yellow(`${process.pid}: ${c.id} ${c.groups}`));
|
|
199
|
-
})
|
|
200
|
-
|
|
201
221
|
let requestGroup = null;
|
|
202
|
-
console.log(chalk.blue(`${process.pid}: Responses :-`));
|
|
203
222
|
for (const [responseId, response] of Object.entries(responses)) {
|
|
204
|
-
console.log(chalk.blue(`${process.pid}: client.id: [${responseId}] response payload: [${JSON.stringify(response.responsePayload)}]`));
|
|
205
223
|
if (response.requestPayload.args.length > 0 && response.requestPayload.args[0].group) {
|
|
206
224
|
requestGroup = response.requestPayload.args[0].group;
|
|
207
|
-
console.log(chalk.blue(`${process.pid}: Group Request: [${requestGroup}]`));
|
|
208
225
|
break;
|
|
209
226
|
}
|
|
210
227
|
}
|
|
211
228
|
|
|
212
229
|
if (requestGroup) {
|
|
213
|
-
console.log(chalk.blue(`${process.pid}: Group Request`));
|
|
214
230
|
const clientsInGroup = Object.values(this.#clients).filter(c => {
|
|
215
231
|
if (c.groups.indexOf(requestGroup) === -1) {
|
|
216
232
|
return false;
|
|
217
233
|
}
|
|
218
234
|
return true;
|
|
219
235
|
});
|
|
220
|
-
console.log(chalk.blue(`${process.pid}: Clients in group: [${requestGroup}] :-`));
|
|
221
|
-
clientsInGroup.forEach(c => {
|
|
222
|
-
console.log(chalk.blue(`${process.pid}: ${c.id}`));
|
|
223
|
-
})
|
|
224
236
|
|
|
225
237
|
// Now make sure that all clients are in the responses
|
|
226
238
|
found = true;
|
|
@@ -229,15 +241,8 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
229
241
|
found = false;
|
|
230
242
|
}
|
|
231
243
|
})
|
|
232
|
-
console.log(chalk.blue(`${process.pid}: found (group) = [${found}]`));
|
|
233
244
|
} else {
|
|
234
|
-
console.log(chalk.blue(`${process.pid}: Non-Group Request`));
|
|
235
|
-
|
|
236
245
|
const clientsInGroup = Object.values(this.#clients)
|
|
237
|
-
console.log(chalk.blue(`${process.pid}: Clients in group (global list): [${requestGroup}] :-`));
|
|
238
|
-
clientsInGroup.forEach(c => {
|
|
239
|
-
console.log(chalk.blue(`${process.pid}: ${c.id}`));
|
|
240
|
-
})
|
|
241
246
|
|
|
242
247
|
// Now make sure that all clients are in the responses
|
|
243
248
|
found = true;
|
|
@@ -246,86 +251,9 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
246
251
|
found = false;
|
|
247
252
|
}
|
|
248
253
|
})
|
|
249
|
-
console.log(chalk.blue(`${process.pid}: found (non-group) = [${found}]`));
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
return found;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
/*
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
Object.values(this.#clients).map(c => {
|
|
259
|
-
if (found) {
|
|
260
|
-
// Check for group payloads
|
|
261
|
-
|
|
262
|
-
console.log(chalk.magenta(`${process.pid}: clients (from ping data)`));
|
|
263
|
-
for (const [key, value] of Object.entries(this.#clients)) {
|
|
264
|
-
console.log(chalk.magenta(`${process.pid}: ${key} = [${value.id} ${value.groups}]`))
|
|
265
|
-
}
|
|
266
|
-
console.log(chalk.blue(`${process.pid}: ${JSON.stringify(responses)}`));
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (responses[c.id]) {
|
|
270
|
-
console.log(chalk.blue(`${process.pid}: 1`));
|
|
271
|
-
if (responses[c.id].requestPayload) {
|
|
272
|
-
console.log(chalk.blue(`${process.pid}: 2`));
|
|
273
|
-
if (responses[c.id].requestPayload.args.length > 0) {
|
|
274
|
-
console.log(chalk.blue(`${process.pid}: 3`));
|
|
275
|
-
if (responses[c.id].requestPayload.args[0].group) {
|
|
276
|
-
console.log(chalk.blue(`${process.pid}: 4`));
|
|
277
|
-
console.log(chalk.magenta(`${process.pid}:requestPayload: [${JSON.stringify(responses[c.id].requestPayload.args[0].group )}]`))
|
|
278
|
-
const requestGroup = responses[c.id].requestPayload.args[0].group;
|
|
279
|
-
//const responseGroup = responses[c.id].responsePayload.args[0].group;
|
|
280
|
-
|
|
281
|
-
console.log(chalk.magenta(`${process.pid}: clients (from ping data)`));
|
|
282
|
-
Object.values(this.#clients).forEach(c => {
|
|
283
|
-
console.log(chalk.magenta(` ${c.groups}`))
|
|
284
|
-
})
|
|
285
|
-
console.log(chalk.magenta(`${process.pid}:`));
|
|
286
|
-
|
|
287
|
-
console.log(chalk.magenta(`${process.pid}: responses so far...`));
|
|
288
|
-
|
|
289
|
-
for (const [key, value] of Object.entries(responses)) {
|
|
290
|
-
console.log(chalk.magenta(`${process.pid}: client.id: [${key}] response payload: [${JSON.stringify(value.responsePayload)}]`));
|
|
291
|
-
}
|
|
292
|
-
console.log(chalk.magenta(`${process.pid}:`));
|
|
293
|
-
|
|
294
|
-
const clientsInGroup = Object.values(this.#clients).filter(c => {
|
|
295
|
-
const foundGroupIndex = c.groups.indexOf(requestGroup);
|
|
296
|
-
if (foundGroupIndex === -1) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
return true;
|
|
300
|
-
});
|
|
301
|
-
clientsInGroup.forEach(c => {
|
|
302
|
-
console.log(`${process.pid}:clientsInGroup: [${c.id}] groups: [${c.groups}]`);
|
|
303
|
-
if (!responses[c.id]) {
|
|
304
|
-
console.log(`${process.pid}: clientsInGroup - not found: [${c.id}]`);
|
|
305
|
-
found = false;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
// Now check if all responses for completed group membership
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
if (!responses[c.id]) {
|
|
314
|
-
found = false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
console.log(chalk.grey(`${process.pid}: ** Testing condition **`))
|
|
321
|
-
if (found === true) {
|
|
322
|
-
console.log(chalk.green(`${process.pid}:Found all messages - should return results`))
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
console.log(chalk.red(`${process.pid}:did not find all messages (yet) ...`))
|
|
326
|
-
return false;
|
|
327
|
-
*/
|
|
328
|
-
return false;
|
|
329
257
|
}
|
|
330
258
|
|
|
331
259
|
#processPayload = (payload: IIPCMessageProcessorIPCPayload, options: any): Promise<JSONObject> => {
|
|
@@ -393,13 +321,30 @@ export class RedisMessageHandler extends TinyEmitter {
|
|
|
393
321
|
|
|
394
322
|
override emit(event: string, ...args: any[]): this {
|
|
395
323
|
(async () => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
324
|
+
try {
|
|
325
|
+
const retVal = await this.#ipcMessageManager?.SendMessage({
|
|
326
|
+
__eventName: event,
|
|
327
|
+
args: args.slice(0, args.length-1)
|
|
328
|
+
} as IEventPayload);
|
|
329
|
+
// Invoke the response callback
|
|
330
|
+
args[args.length-1](retVal);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (this.#options.ignoreEvents) {
|
|
333
|
+
//console.log(chalk.red(`RedisMessageHandler:emit(): ignoreEvents: [${this.#options.ignoreEvents}]`))
|
|
334
|
+
if (this.#options.ignoreEvents.indexOf((error as any).__eventName) !== -1) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
this.#options.logger.error(chalk.red(`RedisMessageHandler:emit(): Error: [${JSON.stringify(error)}]`));
|
|
339
|
+
}
|
|
402
340
|
})();
|
|
403
341
|
return this;
|
|
404
342
|
}
|
|
343
|
+
|
|
344
|
+
emitex = async(event: string, ...args: any[]): Promise<JSONObject> => {
|
|
345
|
+
return (this.#ipcMessageManager as IPCMessageManager).SendMessage({
|
|
346
|
+
__eventName: event,
|
|
347
|
+
args
|
|
348
|
+
} as IEventPayload);
|
|
349
|
+
}
|
|
405
350
|
}
|
package/src/testing/app.ts
CHANGED
|
@@ -108,7 +108,7 @@ const StartTestWorker = () => {
|
|
|
108
108
|
const w1 = new IPCMessageProcessorWorker({
|
|
109
109
|
logger: defaultLogger,
|
|
110
110
|
namespace: 'test1',
|
|
111
|
-
requestResponseMessageTimeout:
|
|
111
|
+
requestResponseMessageTimeout: 5000,
|
|
112
112
|
processPayload: async (payload) => {
|
|
113
113
|
return {
|
|
114
114
|
msg1: `From WORKER: [${process.pid}]`,
|
|
@@ -121,7 +121,7 @@ const StartTestWorker = () => {
|
|
|
121
121
|
const w2 = new IPCMessageProcessorWorker({
|
|
122
122
|
logger: defaultLogger,
|
|
123
123
|
namespace: 'test2',
|
|
124
|
-
requestResponseMessageTimeout:
|
|
124
|
+
requestResponseMessageTimeout: 5000,
|
|
125
125
|
processPayload: async (payload) => {
|
|
126
126
|
return {
|
|
127
127
|
msg2: `From WORKER: [${process.pid}]`,
|
|
@@ -134,7 +134,7 @@ const StartTestWorker = () => {
|
|
|
134
134
|
const w3 = new IPCMessageProcessorWorker({
|
|
135
135
|
logger: defaultLogger,
|
|
136
136
|
namespace: 'zzz',
|
|
137
|
-
requestResponseMessageTimeout:
|
|
137
|
+
requestResponseMessageTimeout: 5000,
|
|
138
138
|
processPayload: async (payload) => {
|
|
139
139
|
switch (payload.requestPayload.cmd) {
|
|
140
140
|
case 'cmd1' : return {
|
|
@@ -271,6 +271,15 @@ if (cluster.isPrimary) {
|
|
|
271
271
|
|
|
272
272
|
LogSystemTelemetry();
|
|
273
273
|
|
|
274
|
+
const stsServiceControl: RedisMessageHandler = new RedisMessageHandler({
|
|
275
|
+
logger: defaultLogger,
|
|
276
|
+
role: 'SERVER',
|
|
277
|
+
redisUrl: goptions.imRedisMessageProcessorUrl,
|
|
278
|
+
namespace: 'stsServiceControl',
|
|
279
|
+
groups: [ ]
|
|
280
|
+
});
|
|
281
|
+
stsServiceControl.Start();
|
|
282
|
+
|
|
274
283
|
setTimeout(() => {
|
|
275
284
|
const p: Record<string, IPCMessageHandler> = { };
|
|
276
285
|
/*
|
|
@@ -326,37 +335,55 @@ if (cluster.isPrimary) {
|
|
|
326
335
|
});
|
|
327
336
|
r1.Start();
|
|
328
337
|
|
|
329
|
-
|
|
338
|
+
const RunTest = async (eventName: string, emitobj: JSONObject) => {
|
|
339
|
+
const start = performance.now();
|
|
340
|
+
try {
|
|
341
|
+
const response = await r1.emitex(eventName, emitobj);
|
|
342
|
+
const duration = performance.now() - start;
|
|
343
|
+
console.log(chalk.cyan(`${process.pid}: Duration: ${duration} Test: [test1] Response(${chalk.bold(eventName)}): [${JSON.stringify(response)}]`));
|
|
344
|
+
} catch (error) {
|
|
345
|
+
const duration = performance.now() - start;
|
|
346
|
+
console.log(chalk.cyan(`${process.pid}: Duration: ${duration} Test: [test1] Response(${chalk.bold(eventName)}): Error: [${JSON.stringify(error)}]`));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
330
349
|
|
|
331
350
|
let i = 0;
|
|
332
351
|
let group = '';
|
|
352
|
+
const maxIterations = 20;
|
|
333
353
|
const xxx = () => {
|
|
334
354
|
setTimeout(() => {
|
|
335
|
-
|
|
336
355
|
i++;
|
|
337
356
|
|
|
357
|
+
if (i > maxIterations) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
console.log(chalk.yellow(`Iteration: [${i}]`));
|
|
362
|
+
|
|
338
363
|
if (i % 2 === 0) {
|
|
339
364
|
group = 'even'
|
|
340
365
|
} else {
|
|
341
366
|
group = 'odd'
|
|
342
367
|
}
|
|
343
368
|
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
369
|
+
const promArray: Promise<void>[] = [ ];
|
|
370
|
+
const start = performance.now();
|
|
371
|
+
promArray.push(
|
|
372
|
+
RunTest('fromprimaryredis', { group, i: i, a: 'a', b: 'b' }),
|
|
373
|
+
RunTest('fromprimaryredis', { group: '2', i: i, a: 'a', b: 'b' }),
|
|
374
|
+
RunTest('fromprimaryredis', { group: '4', i: i, a: 'a', b: 'b' }),
|
|
375
|
+
RunTest('globalmessage', { i: i, a: 'a', b: 'b' })
|
|
376
|
+
);
|
|
377
|
+
(async () => {
|
|
378
|
+
await Promise.all(promArray);
|
|
379
|
+
const duration = performance.now() - start;
|
|
380
|
+
console.log(chalk.green(`${process.pid}: Duration: ${duration} Test: [All Tests Run]`));
|
|
381
|
+
console.log();
|
|
382
|
+
xxx();
|
|
383
|
+
})();
|
|
384
|
+
}, 250);
|
|
358
385
|
}
|
|
359
|
-
xxx();
|
|
386
|
+
setTimeout(() => xxx(), 1000);
|
|
360
387
|
|
|
361
388
|
|
|
362
389
|
|
|
@@ -392,7 +419,23 @@ if (cluster.isPrimary) {
|
|
|
392
419
|
|
|
393
420
|
}, 1000);
|
|
394
421
|
*/
|
|
395
|
-
},
|
|
422
|
+
}, 2000);
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
const ListClients = () => {
|
|
426
|
+
setTimeout(() => {
|
|
427
|
+
Object.values(stsServiceControl.clients).forEach(c => {
|
|
428
|
+
console.log(chalk.gray(`client id: [${c.id}]`));
|
|
429
|
+
console.log(chalk.gray(`client groups: [${c.groups}]`));
|
|
430
|
+
console.log(chalk.gray(`client pingCount: [${c.pingCount}]`));
|
|
431
|
+
console.log(chalk.gray(`client serviceProcessContext: [${JSON.stringify(c.serviceProcessContext)}]`));
|
|
432
|
+
});
|
|
433
|
+
ListClients();
|
|
434
|
+
}, 1000).unref();
|
|
435
|
+
}
|
|
436
|
+
ListClients();
|
|
437
|
+
|
|
438
|
+
|
|
396
439
|
} else {
|
|
397
440
|
new WorkerProcess(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
|
|
398
441
|
//StartTestWorker();
|
|
@@ -406,24 +449,29 @@ if (cluster.isPrimary) {
|
|
|
406
449
|
group = 'odd'
|
|
407
450
|
}
|
|
408
451
|
|
|
452
|
+
let workerId = '0';
|
|
453
|
+
if (cluster.worker) {
|
|
454
|
+
console.log(chalk.blue(`Worker: [${cluster.worker?.id}]`));
|
|
455
|
+
workerId = cluster.worker?.id.toString();
|
|
456
|
+
}
|
|
457
|
+
|
|
409
458
|
const r1: RedisMessageHandler = new RedisMessageHandler({
|
|
410
459
|
logger: defaultLogger,
|
|
411
460
|
role: 'CLIENT',
|
|
412
461
|
redisUrl: goptions.imRedisMessageProcessorUrl,
|
|
413
462
|
namespace: 'mytestapp',
|
|
414
|
-
groups: [ group ]
|
|
463
|
+
groups: [ group, workerId ],
|
|
464
|
+
ignoreEvents: [ 'ping' ]
|
|
415
465
|
});
|
|
416
466
|
r1.Start();
|
|
417
467
|
|
|
418
468
|
r1.on('fromprimaryredis', (arg1: JSONObject, callback: any) => {
|
|
419
|
-
console.log(chalk.greenBright(` -->> ${process.pid}: fromprimaryredis.ON: [${JSON.stringify(arg1)}]`));
|
|
420
469
|
callback( {
|
|
421
470
|
status: `PID: [${process.pid}]: response message from event = fromprimaryredis with args ${JSON.stringify(arg1)}`
|
|
422
471
|
})
|
|
423
472
|
});
|
|
424
473
|
|
|
425
474
|
r1.on('globalmessage', (arg1: JSONObject, callback: any) => {
|
|
426
|
-
console.log(chalk.greenBright(` -->> ${process.pid}: globalmessage.ON: [${JSON.stringify(arg1)}]`));
|
|
427
475
|
callback( {
|
|
428
476
|
status: `PID: [${process.pid}]: response message from event = globalmessage with args ${JSON.stringify(arg1)}`
|
|
429
477
|
})
|
|
@@ -471,5 +519,5 @@ if (cluster.isPrimary) {
|
|
|
471
519
|
}
|
|
472
520
|
}, 1000);
|
|
473
521
|
*/
|
|
474
|
-
},
|
|
522
|
+
}, 2000);
|
|
475
523
|
}
|
package/src/workerprocessbase.ts
CHANGED
|
@@ -27,11 +27,10 @@ import { GetFirstNetworkInterface } from './network'
|
|
|
27
27
|
export class WorkerProcessBase extends ServerProcessBase implements IWorkerProcessBase
|
|
28
28
|
{
|
|
29
29
|
#inFlightMessage: IPCMessages = { }
|
|
30
|
-
#requestResponseMessageTimeout =
|
|
30
|
+
#requestResponseMessageTimeout = 5000; //@@ config
|
|
31
31
|
#redisMessageHandler: RedisMessageHandler | null = null;
|
|
32
32
|
#redisMessageHandlerPing: number = 1000;
|
|
33
33
|
#pingTimeout: NodeJS.Timeout | null = null;
|
|
34
|
-
#instanceId: string = uuidv4();
|
|
35
34
|
|
|
36
35
|
constructor(options: ProcessOptions) {
|
|
37
36
|
super(options);
|
|
@@ -84,7 +83,7 @@ export class WorkerProcessBase extends ServerProcessBase implements IWorkerProce
|
|
|
84
83
|
setTimeout(() => {
|
|
85
84
|
delete this.#inFlightMessage[message.id];
|
|
86
85
|
}, 0).unref();
|
|
87
|
-
this.#LogDebugMessage(chalk.red(`Timeout has occurred after: [${this.#requestResponseMessageTimeout}]ms with message id: [${message.id}]. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
|
|
86
|
+
//this.#LogDebugMessage(chalk.red(`Timeout has occurred after: [${this.#requestResponseMessageTimeout}]ms with message id: [${message.id}]. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
|
|
88
87
|
reject('Did not receive response form parent process.');
|
|
89
88
|
}, this.#requestResponseMessageTimeout) // max message timeout allowed
|
|
90
89
|
};
|
|
@@ -159,8 +158,6 @@ export class WorkerProcessBase extends ServerProcessBase implements IWorkerProce
|
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
GetSystemTelemetry = async () => {
|
|
162
|
-
|
|
163
|
-
|
|
164
161
|
// https://systeminformation.io/
|
|
165
162
|
const valueObject = {
|
|
166
163
|
system: '*',
|
|
@@ -186,7 +183,8 @@ export class WorkerProcessBase extends ServerProcessBase implements IWorkerProce
|
|
|
186
183
|
const dockerContainerStats = await Promise.all(promArray);
|
|
187
184
|
|
|
188
185
|
const sysInfo = {
|
|
189
|
-
|
|
186
|
+
serviceInstanceId: this.options.serviceInstanceId,
|
|
187
|
+
serviceProcessContext: this.options.serviceProcessContext,
|
|
190
188
|
hostname,
|
|
191
189
|
numCPUs,
|
|
192
190
|
hostaddr,
|
|
@@ -266,25 +264,35 @@ export class WorkerProcessBase extends ServerProcessBase implements IWorkerProce
|
|
|
266
264
|
|
|
267
265
|
await this.SetupSTSServer();
|
|
268
266
|
|
|
269
|
-
/*
|
|
270
267
|
this.#redisMessageHandler = new RedisMessageHandler({
|
|
271
268
|
logger: this.options.logger,
|
|
272
269
|
role: 'CLIENT',
|
|
273
270
|
redisUrl: goptions.imRedisMessageProcessorUrl,
|
|
274
271
|
namespace: 'stsServiceControl',
|
|
275
|
-
groups: [ ]
|
|
272
|
+
groups: [ ],
|
|
273
|
+
ignoreEvents: [ 'ping' ],
|
|
274
|
+
processOptions: this.options
|
|
276
275
|
});
|
|
277
276
|
this.#redisMessageHandler.Start();
|
|
278
277
|
|
|
278
|
+
/*
|
|
279
279
|
const ping = () => {
|
|
280
280
|
this.#pingTimeout = setTimeout(() => {
|
|
281
281
|
const pingData = {
|
|
282
|
-
|
|
282
|
+
group: 'stsServiceControlGroup',
|
|
283
|
+
serviceInstanceId: this.options.serviceInstanceId,
|
|
284
|
+
serviceName: this.options.serviceName,
|
|
285
|
+
serviceVersion: this.options.serviceVersion,
|
|
286
|
+
serviceProcessContext: this.options.serviceProcessContext
|
|
283
287
|
}
|
|
284
288
|
if (this.#redisMessageHandler) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
289
|
+
try {
|
|
290
|
+
this.#redisMessageHandler.emit('ping_ex', pingData, (response: any) => {
|
|
291
|
+
console.log(chalk.cyan(` ==>> ${process.pid}: Response(ping): [${JSON.stringify(response)}]`));
|
|
292
|
+
});
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.log(`************************************************`)
|
|
295
|
+
}
|
|
288
296
|
}
|
|
289
297
|
ping();
|
|
290
298
|
}, this.#redisMessageHandlerPing).unref();
|
|
@@ -292,6 +300,8 @@ export class WorkerProcessBase extends ServerProcessBase implements IWorkerProce
|
|
|
292
300
|
ping();
|
|
293
301
|
*/
|
|
294
302
|
|
|
303
|
+
|
|
304
|
+
|
|
295
305
|
// this.#redisMessageHandler.on('GET_SYSTEM_TELEMETRY', async (getSystemTelemetryCommand: JSONObject, callback: any) => {
|
|
296
306
|
// callback({ instanceId: this.#instanceId, process: process.pid, systemTelemetry: getSystemTelemetryCommand });
|
|
297
307
|
/*
|
package/types/index.d.ts
CHANGED
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipcMessageManager.d.ts","sourceRoot":"","sources":["../src/ipcMessageManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipcMessageManager.d.ts","sourceRoot":"","sources":["../src/ipcMessageManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,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