@superhero/eventflow-hub 4.0.13 → 4.0.15
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/index.js +41 -25
- package/manager/spokes.js +5 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -54,6 +54,15 @@ export default class Hub
|
|
|
54
54
|
this.log = new Log({ label: `[${config.NAME}]` })
|
|
55
55
|
this.certificates = new CertificatesManager(config.NAME, this.#hubID, config.certificates, db, this.log)
|
|
56
56
|
|
|
57
|
+
for(const level of [ 'info', 'warn', 'fail' ])
|
|
58
|
+
{
|
|
59
|
+
this.log[level] = (...args) =>
|
|
60
|
+
{
|
|
61
|
+
this.log.emit(level, ...args)
|
|
62
|
+
return this.log.basic(...args)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
this.channel.on('record', this.#onRecord.bind(this))
|
|
58
67
|
}
|
|
59
68
|
|
|
@@ -151,15 +160,13 @@ export default class Hub
|
|
|
151
160
|
|
|
152
161
|
async #onServerError(error)
|
|
153
162
|
{
|
|
154
|
-
this.log.fail`server error [${error.code}] ${error.message}`
|
|
155
|
-
const message = `server error [${error.code}] ${error.message}`
|
|
163
|
+
const message = this.log.fail`server error [${error.code}] ${error.message}`
|
|
156
164
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
157
165
|
}
|
|
158
166
|
|
|
159
167
|
async #onClientError(client, error)
|
|
160
168
|
{
|
|
161
|
-
this.log.fail`observed client error [${error.code}] ${error.message} in ${client.id}`
|
|
162
|
-
const message = `observed client error [${error.code}] ${error.message} in ${client.id}`
|
|
169
|
+
const message = this.log.fail`observed client error [${error.code}] ${error.message} in ${client.id}`
|
|
163
170
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
164
171
|
}
|
|
165
172
|
|
|
@@ -198,8 +205,7 @@ export default class Hub
|
|
|
198
205
|
client.setKeepAlive(true, this.config.KEEP_ALIVE_INTERVAL)
|
|
199
206
|
client.resume()
|
|
200
207
|
|
|
201
|
-
this.log.info`connected ${client.id}`
|
|
202
|
-
const message = `connected ${client.id}`
|
|
208
|
+
const message = this.log.info`connected ${client.id}`
|
|
203
209
|
await this.db.persistLog({ agent:this.#hubID, message })
|
|
204
210
|
}
|
|
205
211
|
|
|
@@ -207,8 +213,7 @@ export default class Hub
|
|
|
207
213
|
{
|
|
208
214
|
this.spokes.delete(client)
|
|
209
215
|
this.subscribers.deleteBySocket(client)
|
|
210
|
-
this.log.info`disconnected ${client.id}`
|
|
211
|
-
const message = `disconnected ${client.id}`
|
|
216
|
+
const message = this.log.info`disconnected ${client.id}`
|
|
212
217
|
await this.db.persistLog({ agent:this.#hubID, message })
|
|
213
218
|
}
|
|
214
219
|
|
|
@@ -335,9 +340,9 @@ export default class Hub
|
|
|
335
340
|
}
|
|
336
341
|
catch(error)
|
|
337
342
|
{
|
|
338
|
-
this.log.fail`failed to connect to peer hub ${hubID} [${error.code}] ${error.message}`
|
|
339
|
-
const message = `failed to connect to peer hub ${hubID} [${error.code}] ${error.message}`
|
|
343
|
+
const message = this.log.fail`failed to connect to peer hub ${hubID} [${error.code}] ${error.message}`
|
|
340
344
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
345
|
+
await this.db.updateHubToQuit(hubID)
|
|
341
346
|
}
|
|
342
347
|
}
|
|
343
348
|
}
|
|
@@ -356,12 +361,10 @@ export default class Hub
|
|
|
356
361
|
dynamicConfig = { servername, host, port, ca, cert, key, passphrase, timeout },
|
|
357
362
|
peerHubConfig = deepmerge(dynamicConfig, this.config.TCP_SOCKET_CLIENT_OPTIONS),
|
|
358
363
|
peerHub = await this.channel.createTlsClient(peerHubConfig)
|
|
359
|
-
|
|
360
|
-
this.log.info`peer hub connection established ${peerHub.id}`
|
|
364
|
+
|
|
361
365
|
peerHub.id = peerHub.getPeerCertificate().subject.UID
|
|
362
366
|
this.channel.transmit(peerHub, [ 'online', this.#hubID, this.config.EXTERNAL_IP, this.config.EXTERNAL_PORT ])
|
|
363
|
-
this.log.info`broadcasted online status to peer hub ${peerHub.id}`
|
|
364
|
-
const message = `broadcasted online status to peer hub ${peerHub.id}`
|
|
367
|
+
const message = this.log.info`broadcasted online status to peer hub ${peerHub.id}`
|
|
365
368
|
await this.db.persistLog({ agent:this.#hubID, message })
|
|
366
369
|
|
|
367
370
|
peerHub.end()
|
|
@@ -374,15 +377,34 @@ export default class Hub
|
|
|
374
377
|
*/
|
|
375
378
|
async #sheduledInterval(delay)
|
|
376
379
|
{
|
|
380
|
+
const signal = this.abortion.signal
|
|
381
|
+
|
|
382
|
+
if(signal.aborted)
|
|
383
|
+
{
|
|
384
|
+
return
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if(0 === this.spokes.amount
|
|
388
|
+
&& await this.db.hasHubQuit(this.#hubID))
|
|
389
|
+
{
|
|
390
|
+
const message = this.log.warn`hub was registered as "quit" by peer hub, probably caused by network issues between peer hubs`
|
|
391
|
+
await this.db.persistLog({ agent:this.#hubID, message })
|
|
392
|
+
return await this.destroy()
|
|
393
|
+
}
|
|
394
|
+
|
|
377
395
|
try
|
|
378
396
|
{
|
|
379
397
|
const
|
|
380
398
|
readScheduledEvents = this.db.readEventsScheduled.bind(this.db),
|
|
381
|
-
signal = this.abortion.signal,
|
|
382
399
|
asyncIterator = asyncInterval(delay, readScheduledEvents, { signal })
|
|
383
400
|
|
|
384
401
|
for await (const sheduledEvents of asyncIterator)
|
|
385
402
|
{
|
|
403
|
+
if(signal.aborted)
|
|
404
|
+
{
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
|
|
386
408
|
for(const scheduledEvent of await sheduledEvents())
|
|
387
409
|
{
|
|
388
410
|
if(signal.aborted)
|
|
@@ -407,8 +429,7 @@ export default class Hub
|
|
|
407
429
|
}
|
|
408
430
|
catch (error)
|
|
409
431
|
{
|
|
410
|
-
this.log.fail`failed to execute scheduled event ${id}: ${domain} › ${name} [${error.code}] ${error.message}`
|
|
411
|
-
const message = `failed to execute scheduled event ${id}: ${domain} › ${name} [${error.code}] ${error.message}`
|
|
432
|
+
const message = this.log.fail`failed to execute scheduled event ${id}: ${domain} › ${name} [${error.code}] ${error.message}`
|
|
412
433
|
await this.db.updateEventScheduledFailed(domain, id)
|
|
413
434
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
414
435
|
throw error
|
|
@@ -420,8 +441,7 @@ export default class Hub
|
|
|
420
441
|
}
|
|
421
442
|
else
|
|
422
443
|
{
|
|
423
|
-
this.log.fail`failed to execute already consumed scheduled event ${id}: ${domain} › ${name}`
|
|
424
|
-
const message = `failed to execute already consumed scheduled event ${id}: ${domain} › ${name}`
|
|
444
|
+
const message = this.log.fail`failed to execute already consumed scheduled event ${id}: ${domain} › ${name}`
|
|
425
445
|
await this.db.updateEventScheduledFailed(domain, id)
|
|
426
446
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
427
447
|
}
|
|
@@ -430,16 +450,12 @@ export default class Hub
|
|
|
430
450
|
}
|
|
431
451
|
catch(error)
|
|
432
452
|
{
|
|
433
|
-
this.log.fail`failed to execute scheduled interval ${error.message} [${error.code}]`
|
|
434
|
-
const message = `failed to execute scheduled interval ${error.message} [${error.code}]`
|
|
453
|
+
const message = this.log.fail`failed to execute scheduled interval ${error.message} [${error.code}]`
|
|
435
454
|
await this.db.persistLog({ agent:this.#hubID, message, error })
|
|
436
455
|
}
|
|
437
456
|
finally
|
|
438
457
|
{
|
|
439
|
-
|
|
440
|
-
{
|
|
441
|
-
setImmediate(this.#sheduledInterval.bind(this, delay))
|
|
442
|
-
}
|
|
458
|
+
setImmediate(this.#sheduledInterval.bind(this, delay))
|
|
443
459
|
}
|
|
444
460
|
}
|
|
445
461
|
}
|
package/manager/spokes.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/eventflow-hub",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.15",
|
|
4
4
|
"description": "Eventflow hub is the central server component in the eventflow ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eventflow",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@superhero/id-name-generator": "^4.0.0",
|
|
18
18
|
"@superhero/log": "^4.0.1",
|
|
19
19
|
"@superhero/eventflow-certificates": "^4.0.7",
|
|
20
|
-
"@superhero/eventflow-db": "^4.2.
|
|
20
|
+
"@superhero/eventflow-db": "^4.2.4",
|
|
21
21
|
"@superhero/tcp-record-channel": "^4.2.2",
|
|
22
22
|
"@superhero/deep": "^4.2.0"
|
|
23
23
|
},
|