@superhero/eventflow-hub 4.0.3 → 4.0.4
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 +17 -7
- package/manager/spokes.js +1 -4
- package/manager/spokes.test.js +3 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -24,7 +24,11 @@ export function locate(locator)
|
|
|
24
24
|
export default class Hub
|
|
25
25
|
{
|
|
26
26
|
#hubID
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
abortion = new AbortController()
|
|
29
|
+
channel = new Channel()
|
|
30
|
+
spokes = new SpokesManager()
|
|
31
|
+
subscribers = new SubscribersManager()
|
|
28
32
|
|
|
29
33
|
get hubID()
|
|
30
34
|
{
|
|
@@ -45,11 +49,8 @@ export default class Hub
|
|
|
45
49
|
this.#hubID = (new IdNameGenerator().generateId() + '.' + config.NAME).toUpperCase()
|
|
46
50
|
this.config = config
|
|
47
51
|
this.db = db
|
|
48
|
-
this.abortion = new AbortController()
|
|
49
52
|
this.log = new Log({ label: `[${config.NAME}]` })
|
|
50
53
|
this.certificates = new CertificatesManager(config.NAME, this.#hubID, config.certificates, db, this.log)
|
|
51
|
-
this.spokes = new SpokesManager()
|
|
52
|
-
this.subscribers = new SubscribersManager()
|
|
53
54
|
|
|
54
55
|
this.channel.on('record', this.#onRecord.bind(this))
|
|
55
56
|
}
|
|
@@ -63,11 +64,20 @@ export default class Hub
|
|
|
63
64
|
|
|
64
65
|
async destroy()
|
|
65
66
|
{
|
|
66
|
-
|
|
67
|
+
const reason = new Error('hub is destroyed')
|
|
68
|
+
reason.code = 'E_EVENTFLOW_HUB_DESTROYED'
|
|
69
|
+
|
|
70
|
+
this.abortion.abort(reason)
|
|
67
71
|
this.server?.close()
|
|
72
|
+
|
|
73
|
+
for(const socket of this.spokes.all)
|
|
74
|
+
{
|
|
75
|
+
socket.end()
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
this.spokes.destroy()
|
|
69
79
|
this.subscribers.destroy()
|
|
70
|
-
this.log.warn`
|
|
80
|
+
this.log.warn`destroyed`
|
|
71
81
|
await this.db.updateHubToQuit(this.#hubID)
|
|
72
82
|
setTimeout(() => this.db.close(), 500)
|
|
73
83
|
}
|
|
@@ -269,7 +279,7 @@ export default class Hub
|
|
|
269
279
|
|
|
270
280
|
async #attemptToConsumeAndBroadcastPublishedMessage(domain, id, name, pid)
|
|
271
281
|
{
|
|
272
|
-
const consumed = await this.db.updateEventPublishedToConsumedByHub(
|
|
282
|
+
const consumed = await this.db.updateEventPublishedToConsumedByHub(id, this.#hubID)
|
|
273
283
|
|
|
274
284
|
if(consumed)
|
|
275
285
|
{
|
package/manager/spokes.js
CHANGED
package/manager/spokes.test.js
CHANGED
|
@@ -34,15 +34,14 @@ suite('@superhero/eventflow-hub/manager/spokes', () =>
|
|
|
34
34
|
test('Destroy all sockets', async () =>
|
|
35
35
|
{
|
|
36
36
|
const manager = new SpokesManager()
|
|
37
|
-
const socket1 = { id: 'socket1'
|
|
38
|
-
const socket2 = { id: 'socket2'
|
|
37
|
+
const socket1 = { id: 'socket1' }
|
|
38
|
+
const socket2 = { id: 'socket2' }
|
|
39
39
|
|
|
40
40
|
manager.add(socket1)
|
|
41
41
|
manager.add(socket2)
|
|
42
42
|
manager.destroy()
|
|
43
43
|
|
|
44
|
-
assert.strictEqual(
|
|
45
|
-
assert.strictEqual(socket2.destroyed, true)
|
|
44
|
+
assert.strictEqual(manager.all.length, 0)
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
test('Handle deleting non-existent socket gracefully', async () =>
|