Forráskód Böngészése

fix: some issues, and made sub-tasks auto skip the queue, filtered common console messages

Kristian Vos 4 éve
szülő
commit
9be27b3315
4 módosított fájl, 60 hozzáadás és 2 törlés
  1. 12 1
      backend/core.js
  2. 36 0
      backend/index.js
  3. 6 1
      backend/logic/notifications.js
  4. 6 0
      backend/logic/utils.js

+ 12 - 1
backend/core.js

@@ -149,7 +149,18 @@ class CoreClass {
         this.log("INFO", `Running job ${job.name}`);
         const startTime = Date.now();
         this.runningJobs.push(job);
-        this[job.name](job.payload)
+        const newThis = Object.assign(
+            Object.create(Object.getPrototypeOf(this)),
+            this
+        );
+        newThis.runJob = (...args) => {
+            if (args.length === 2) args.push({});
+            args[2].bypassQueue = true;
+            return this.runJob.apply(this, args);
+        };
+        this[job.name]
+            .apply(newThis, [job.payload])
+            // this[job.name](job.payload)
             .then((response) => {
                 this.log("INFO", `Ran job ${job.name} successfully`);
                 this.jobStatistics[job.name].successful++;

+ 36 - 0
backend/index.js

@@ -11,6 +11,39 @@ process.on("uncaughtException", (err) => {
     console.log(`UNCAUGHT EXCEPTION: ${err.stack}`);
 });
 
+const blacklistedConsoleLogs = [
+    "Running job IO",
+    "Ran job IO successfully",
+    "Running job HGET",
+    "Ran job HGET successfully",
+    "Running job HGETALL",
+    "Ran job HGETALL successfully",
+    "Running job GET_ERROR",
+    "Ran job GET_ERROR successfully",
+    "Running job GET_SCHEMA",
+    "Ran job GET_SCHEMA successfully",
+    "Running job SUB",
+    "Ran job SUB successfully",
+    "Running job GET_MODEL",
+    "Ran job GET_MODEL successfully",
+    "Running job HSET",
+    "Ran job HSET successfully",
+    "Running job CAN_USER_VIEW_STATION",
+    "Ran job CAN_USER_VIEW_STATION successfully",
+];
+
+const oldConsole = {};
+oldConsole.log = console.log;
+
+console.log = (...args) => {
+    const string = util.format.apply(null, args);
+    let blacklisted = false;
+    blacklistedConsoleLogs.forEach((blacklistedConsoleLog) => {
+        if (string.indexOf(blacklistedConsoleLog) !== -1) blacklisted = true;
+    });
+    if (!blacklisted) oldConsole.log.apply(null, args);
+};
+
 const fancyConsole = config.get("fancyConsole");
 
 // class ModuleManager {
@@ -340,6 +373,9 @@ process.stdin.on("data", function(data) {
 
         console.log(moduleManager.modules[parts[1]].jobStatistics);
     }
+    if (data.toString().startsWith("debug")) {
+        moduleManager.modules["utils"].runJob("DEBUG");
+    }
 });
 
 module.exports = moduleManager;

+ 6 - 1
backend/logic/notifications.js

@@ -190,7 +190,12 @@ class NotificationsModule extends CoreClass {
                     (subscription) => subscription.originalName === payload.name
                 )
             )
-                return reject(new Error("Already subscribed."));
+                return resolve({
+                    subscription: subscriptions.find(
+                        (subscription) =>
+                            subscription.originalName === payload.name
+                    ),
+                });
             let subscription = {
                 originalName: payload.name,
                 name: crypto

+ 6 - 0
backend/logic/utils.js

@@ -757,6 +757,12 @@ class UtilsModule extends CoreClass {
             resolve(`https://www.gravatar.com/avatar/${hash}`);
         });
     }
+
+    DEBUG(payload) {
+        return new Promise((resolve, reject) => {
+            resolve();
+        });
+    }
 }
 
 module.exports = new UtilsModule();