Browse Source

Fixed issue where station wouldn't always skip

Kristian Vos 4 years ago
parent
commit
2968e81a57
3 changed files with 52 additions and 29 deletions
  1. 11 9
      backend/core.js
  2. 21 1
      backend/logic/api.js
  3. 20 19
      backend/logic/stations.js

+ 11 - 9
backend/core.js

@@ -439,15 +439,6 @@ export default class CoreClass {
 
 		// console.log(321, parentJob);
 
-		if (
-			config.debug &&
-			config.debug.stationIssue === true &&
-			config.debug.captureJobs &&
-			config.debug.captureJobs.indexOf(name) !== -1
-		) {
-			this.moduleManager.debugJobs.all.push(job);
-		}
-
 		job.setStatus("QUEUED");
 
 		// if (options.bypassQueue) this._runJob(job, options, () => {});
@@ -458,6 +449,16 @@ export default class CoreClass {
 			this.priorities[name] ? this.priorities[name] : 10
 		);
 		this.jobQueue.push(job, _priority);
+
+		if (
+			config.debug &&
+			config.debug.stationIssue === true &&
+			config.debug.captureJobs &&
+			config.debug.captureJobs.indexOf(name) !== -1
+		) {
+			this.moduleManager.debugJobs.all.push({ job, _priority });
+		}
+
 		// }
 
 		return deferredPromise.promise;
@@ -510,6 +511,7 @@ export default class CoreClass {
 							this.moduleManager.debugJobs.completed.push({
 								status: "success",
 								job,
+								priority: job.task.priority,
 								response
 							});
 						}

+ 21 - 1
backend/logic/api.js

@@ -231,7 +231,27 @@ class _APIModule extends CoreClass {
 					// 				});
 					// 			}
 
-					// 			res.json(responseObject);
+					// 			const responseJson = JSON.stringify(responseObject, (key, value) => {
+					// 				// console.log(key, value);
+					// 				if (
+					// 					key === "module" ||
+					// 					key === "task" ||
+					// 					key === "onFinish" ||
+					// 					key === "server" ||
+					// 					key === "nsp" ||
+					// 					key === "socket" ||
+					// 					key === "res" ||
+					// 					key === "client" ||
+					// 					key === "_idleNext" ||
+					// 					key === "_idlePrev"
+					// 				) {
+					// 					return undefined;
+					// 				}
+					// 				if (key === "parentJob" && value) return value.toString();
+					// 				return value;
+					// 			});
+
+					// 			res.end(responseJson);
 					// 		}
 					// 	);
 					// });

+ 20 - 19
backend/logic/stations.js

@@ -221,27 +221,28 @@ class _StationsModule extends CoreClass {
 							name: `stations.nextSong?id=${station._id}`
 						})
 							.then()
-							.catch();
-
-						NotificationsModule.runJob(
-							"SUBSCRIBE",
-							{
-								name: `stations.nextSong?id=${station._id}`,
-								cb: () =>
-									StationsModule.runJob("SKIP_STATION", {
-										stationId: station._id
-									}),
-								unique: true,
-								station
-							},
-							this
-						)
-							.then()
-							.catch();
+							.catch()
+							.finally(() => {
+								NotificationsModule.runJob(
+									"SUBSCRIBE",
+									{
+										name: `stations.nextSong?id=${station._id}`,
+										cb: () =>
+											StationsModule.runJob("SKIP_STATION", {
+												stationId: station._id
+											}),
+										unique: true,
+										station
+									},
+									this
+								)
+									.then()
+									.catch();
 
-						if (station.paused) return next(true, station);
+								if (station.paused) return next(true, station);
 
-						return next(null, station);
+								return next(null, station);
+							});
 					},
 					(station, next) => {
 						if (!station.currentSong) {