Procházet zdrojové kódy

fix: cache/notifications modules would sometimes claim to be ready when they weren't

Kristian Vos před 1 rokem
rodič
revize
939d52d00c
2 změnil soubory, kde provedl 13 přidání a 7 odebrání
  1. 6 3
      backend/logic/cache/index.js
  2. 7 4
      backend/logic/notifications.js

+ 6 - 3
backend/logic/cache/index.js

@@ -76,13 +76,16 @@ class _CacheModule extends CoreClass {
 				this.log("ERROR", `Error ${err.message}.`);
 			});
 
-			this.client.connect().then(async () => {
-				this.log("INFO", "Connected succesfully.");
-
+			this.client.on("ready", () => {
+				this.log("INFO", "Redis is ready.");
 				if (this.getStatus() === "INITIALIZING") resolve();
 				else if (this.getStatus() === "FAILED" || this.getStatus() === "RECONNECTING") this.setStatus("READY");
 			});
 
+			this.client.connect().then(async () => {
+				this.log("INFO", "Connected succesfully.");
+			});
+
 			// TODO move to a better place
 			CacheModule.runJob("KEYS", { pattern: "longJobs.*" }).then(keys => {
 				async.eachLimit(keys, 1, (key, next) => {

+ 7 - 4
backend/logic/notifications.js

@@ -56,6 +56,13 @@ class _NotificationsModule extends CoreClass {
 				this.log("ERROR", `Error ${err.message}.`);
 			});
 
+			this.pub.on("ready", () => {
+				this.log("INFO", "Pub is ready.");
+				if (this.getStatus() === "INITIALIZING") resolve();
+				else if (this.getStatus() === "LOCKDOWN" || this.getStatus() === "RECONNECTING")
+					this.setStatus("INITIALIZED");
+			});
+
 			this.pub.connect().then(async () => {
 				this.log("INFO", "Pub connected succesfully.");
 
@@ -85,10 +92,6 @@ class _NotificationsModule extends CoreClass {
 						);
 						this.log("STATION_ISSUE", `Getting notify-keyspace-events gave an error. ${err}.`);
 					});
-
-				if (this.getStatus() === "INITIALIZING") resolve();
-				else if (this.getStatus() === "LOCKDOWN" || this.getStatus() === "RECONNECTING")
-					this.setStatus("INITIALIZED");
 			});
 
 			this.sub = this.pub.duplicate();