dashboard works

This commit is contained in:
NoLogicAlan committed 2026-05-08 02:26:19 +03:00
1 parent 624d00cff6
commit 8a55431eec
5 files changed
+118 -451

No files matched your search

+3 -23
View File
@@ -61,9 +61,7 @@ export class RedisHandler {
try {
await this.client.connect();
logger.redis("[Redis/Main] Connected");
// Do NOT call readyMessage() here — the subscriber is not yet listening
// on the "request" channel. If we announce before subscribing, the
// backend will send requests that we miss, causing a timeout.
this.readyMessage();
} catch (e) {
logger.error("[Redis/Main] Initial connection failed:", e.message);
}
@@ -72,10 +70,7 @@ export class RedisHandler {
await this.subscriber.connect();
logger.redis("[Redis/Subscriber] Connected");
// CRITICAL: Await both subscriptions so they are guaranteed to be active
// before we announce readiness. Without awaiting, there is a window
// where the backend sends requests that this bot cannot yet receive.
await this.subscriber.subscribe("request", async (m) => {
this.subscriber.subscribe("request", async (m) => {
if (this._destroyed) return;
try {
const payload = JSON.parse(m);
@@ -88,20 +83,10 @@ export class RedisHandler {
}));
} catch (e) {
logger.error("[Redis/Subscriber] Request handler error:", e.message);
// Always send a response so the backend doesn't time out.
// Parse the id from the raw message so we can reply even when
// the handler threw before producing a result.
try {
const payload = JSON.parse(m);
this.send("response", JSON.stringify({
id: payload.id,
content: { error: "Internal bot error: " + e.message },
}));
} catch (_) { /* payload was unparseable — nothing we can do */ }
}
});
await this.subscriber.subscribe("info", (m) => {
this.subscriber.subscribe("info", (m) => {
if (this._destroyed) return;
try {
const data = JSON.parse(m);
@@ -112,11 +97,6 @@ export class RedisHandler {
logger.warn("[Redis/Subscriber] Info handler error:", e.message);
}
});
// NOW announce readiness — the subscriber is guaranteed to be listening
// on both "request" and "info", so the backend's requests will be
// received and handled.
this.readyMessage();
} catch (e) {
logger.error("[Redis/Subscriber] Initial connection failed:", e.message);
}