瀏覽代碼

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

Kristian Vos 1 年之前
父節點
當前提交
939d52d00c
共有 2 個文件被更改,包括 13 次插入7 次删除
  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();