dashboard

This commit is contained in:
NoLogicAlan committed 2026-05-08 00:16:14 +03:00
1 parent 37c29ca6cd
commit 09580cebf5
2 files changed
+36 -6

No files matched your search

+23 -3
View File
@@ -61,7 +61,9 @@ export class RedisHandler {
try {
await this.client.connect();
logger.redis("[Redis/Main] Connected");
this.readyMessage();
// 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.
} catch (e) {
logger.error("[Redis/Main] Initial connection failed:", e.message);
}
@@ -70,7 +72,10 @@ export class RedisHandler {
await this.subscriber.connect();
logger.redis("[Redis/Subscriber] Connected");
this.subscriber.subscribe("request", async (m) => {
// 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) => {
if (this._destroyed) return;
try {
const payload = JSON.parse(m);
@@ -83,10 +88,20 @@ 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 */ }
}
});
this.subscriber.subscribe("info", (m) => {
await this.subscriber.subscribe("info", (m) => {
if (this._destroyed) return;
try {
const data = JSON.parse(m);
@@ -97,6 +112,11 @@ 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);
}