Browse Source

fix: stations & songs module wouldn't initialize sometimes

Kristian Vos 4 years ago
parent
commit
6ebc650d80

+ 1 - 1
backend/logic/actions/playlists.js

@@ -437,7 +437,7 @@ let lib = {
                 (playlist, next) => {
                     utils
                         .runJob("SHUFFLE", { array: playlist.songs })
-                        .then((songs) => next(null, songs))
+                        .then((result) => next(null, result.array))
                         .catch(next);
                 },
 

+ 0 - 5
backend/logic/actions/stations.js

@@ -577,11 +577,6 @@ module.exports = {
                         .runJob("GET_STATION", { stationId })
                         .then((station) => next(null, station))
                         .catch(next);
-
-                    stations
-                        .runJob("GET_STATION", { stationId })
-                        .then((station) => next(null, station))
-                        .catch(next);
                 },
 
                 (station, next) => {

+ 6 - 2
backend/logic/actions/utils.js

@@ -15,7 +15,7 @@ module.exports = {
                 },
 
                 (modules, next) => {
-                    console.log(modules, next);
+                    // console.log(modules, next);
                     next(
                         null,
                         Object.keys(modules).map((moduleName) => {
@@ -65,7 +65,10 @@ module.exports = {
                 },
             ],
             async (err, module) => {
-                console.log(module.runningJobs);
+                    return task.data;
+                });
+
+                // console.log(module.runningJobs);
                 if (err && err !== true) {
                     err = await utils.runJob("GET_ERROR", { error: err });
                     console.log(
@@ -85,6 +88,7 @@ module.exports = {
                         message: "Successfully got module info.",
                         runningJobs: module.runningJobs,
                         jobStatistics: module.jobStatistics,
+                        jobsInQueue,
                     });
                 }
             }

+ 1 - 1
backend/logic/notifications.js

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

+ 3 - 2
backend/logic/songs.js

@@ -73,7 +73,7 @@ class SongsModule extends CoreClass {
                                     .runJob("HSET", {
                                         table: "songs",
                                         key: song.songId,
-                                        value: songSchema.song(song),
+                                        value: songSchema(song),
                                     })
                                     .then(() => next())
                                     .catch(next);
@@ -114,7 +114,8 @@ class SongsModule extends CoreClass {
                     (next) => {
                         if (!mongoose.Types.ObjectId.isValid(payload.id))
                             return next("Id is not a valid ObjectId.");
-                        this.runJob("HGET", { table: "songs", key: payload.id })
+                        this.cache
+                            .runJob("HGET", { table: "songs", key: payload.id })
                             .then((song) => next(null, song))
                             .catch(next);
                     },

+ 30 - 12
backend/logic/stations.js

@@ -209,7 +209,10 @@ class StationsModule extends CoreClass {
                     (next) => {
                         this.runJob(
                             "GET_STATION",
-                            { stationId: payload.stationId },
+                            {
+                                stationId: payload.stationId,
+                                bypassQueue: payload.bypassQueue,
+                            },
                             { bypassQueue: payload.bypassQueue }
                         )
                             .then((station) => next(null, station))
@@ -264,7 +267,10 @@ class StationsModule extends CoreClass {
                         ) {
                             this.runJob(
                                 "SKIP_STATION",
-                                { stationId: station._id },
+                                {
+                                    stationId: station._id,
+                                    bypassQueue: payload.bypassQueue,
+                                },
                                 { bypassQueue: payload.bypassQueue }
                             )
                                 .then((station) => next(null, station))
@@ -351,28 +357,38 @@ class StationsModule extends CoreClass {
 
                         this.utils
                             .runJob("SHUFFLE", { array: playlist })
-                            .then((playlist) => next(null, playlist))
+                            .then((result) => next(null, result.array))
                             .catch(next);
                     },
 
                     (playlist, next) => {
-                        this.runJob("CALCULATE_OFFICIAL_PLAYLIST_LIST", {
-                            stationId,
-                            songList: playlist,
-                        })
+                        this.runJob(
+                            "CALCULATE_OFFICIAL_PLAYLIST_LIST",
+                            {
+                                stationId: payload.stationId,
+                                songList: playlist,
+                                bypassQueue: payload.bypassQueue,
+                            },
+                            { bypassQueue: payload.bypassQueue }
+                        )
                             .then(() => next(null, playlist))
                             .catch(next);
                     },
 
                     (playlist, next) => {
                         stationModel.updateOne(
-                            { _id: station._id },
+                            { _id: payload.station._id },
                             { $set: { playlist: playlist } },
                             { runValidators: true },
                             (err) => {
-                                this.runJob("UPDATE_STATION", {
-                                    stationId: station._id,
-                                })
+                                this.runJob(
+                                    "UPDATE_STATION",
+                                    {
+                                        stationId: payload.station._id,
+                                        bypassQueue: payload.bypassQueue,
+                                    },
+                                    { bypassQueue: payload.bypassQueue }
+                                )
                                     .then(() => next(null, playlist))
                                     .catch(next);
                             }
@@ -614,6 +630,7 @@ class StationsModule extends CoreClass {
                             "GET_STATION",
                             {
                                 stationId: payload.stationId,
+                                bypassQueue: payload.bypassQueue,
                             },
                             { bypassQueue: payload.bypassQueue }
                         )
@@ -846,7 +863,8 @@ class StationsModule extends CoreClass {
                                                 station,
                                                 bypassQueue:
                                                     payload.bypassQueue,
-                                            }
+                                            },
+                                            { bypassQueue: payload.bypassQueue }
                                         )
                                             .then((newPlaylist) => {
                                                 this.songs.getSong(

+ 1 - 1
backend/logic/utils.js

@@ -725,7 +725,7 @@ class UtilsModule extends CoreClass {
                 array[randomIndex] = temporaryValue;
             }
 
-            return array;
+            resolve({ array });
         });
     }