2026-03-12 16:46:30 +00:00
|
|
|
class BackendRegistry {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.backends = new Map();
|
2026-03-13 11:52:48 +00:00
|
|
|
this.log = require('./event-bus').log;
|
2026-03-12 16:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
register(serviceId, ws) {
|
|
|
|
|
this.backends.set(serviceId, {
|
|
|
|
|
ws,
|
|
|
|
|
connectedAt: new Date().toISOString(),
|
|
|
|
|
lastPing: null,
|
|
|
|
|
});
|
2026-03-13 11:52:48 +00:00
|
|
|
this.log('info', `[registry] registered backend: ${serviceId}`);
|
2026-03-12 16:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unregister(serviceId) {
|
|
|
|
|
if (this.backends.has(serviceId)) {
|
|
|
|
|
this.backends.delete(serviceId);
|
2026-03-13 11:52:48 +00:00
|
|
|
this.log('info', `[registry] unregistered backend: ${serviceId}`);
|
2026-03-12 16:46:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get(serviceId) {
|
|
|
|
|
const entry = this.backends.get(serviceId);
|
|
|
|
|
return entry ? entry.ws : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list() {
|
|
|
|
|
return Array.from(this.backends.entries()).map(([serviceId, entry]) => ({
|
|
|
|
|
serviceId,
|
|
|
|
|
connectedAt: entry.connectedAt,
|
|
|
|
|
lastPing: entry.lastPing,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePing(serviceId) {
|
|
|
|
|
const entry = this.backends.get(serviceId);
|
|
|
|
|
if (entry) {
|
|
|
|
|
entry.lastPing = new Date().toISOString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count() {
|
|
|
|
|
return this.backends.size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = new BackendRegistry();
|