Browse Source

Fixed some issues with child job unpausing completed jobs

Kristian Vos 4 years ago
parent
commit
ff83661a14
2 changed files with 28 additions and 35 deletions
  1. 11 8
      backend/core.js
  2. 17 27
      backend/logic/stations.js

+ 11 - 8
backend/core.js

@@ -620,14 +620,17 @@ export default class CoreClass {
 							job.parentJob &&
 							job.parentJob.childJobs.find(childJob => childJob.status !== "FINISHED") === undefined
 						) {
-							this.log(
-								"INFO",
-								`Requeing/resuming job ${
-									job.parentJob.name
-								} (${job.parentJob.toString()}) since all child jobs are complete.`
-							);
-							job.parentJob.setStatus("REQUEUED");
-							job.parentJob.module.jobQueue.resumeRunningJob(job.parentJob);
+							if (job.parentJob.status !== "WAITING_ON_CHILD_JOB") {
+								this.log(
+									"ERROR",
+									`Job ${
+										job.parentJob.name
+									} (${job.parentJob.toString()}) had a child job complete even though it is not waiting on a child job. This should never happen.`
+								);
+							} else {
+								job.parentJob.setStatus("REQUEUED");
+								job.parentJob.module.jobQueue.resumeRunningJob(job.parentJob);
+							}
 						}
 						resolve();
 					});

+ 17 - 27
backend/logic/stations.js

@@ -949,35 +949,25 @@ class _StationsModule extends CoreClass {
 							});
 						}
 
-						if (station.currentSong !== null && station.currentSong.songId !== undefined) {
-							WSModule.runJob("SOCKETS_JOIN_SONG_ROOM", {
-								sockets: await WSModule.runJob(
-									"GET_SOCKETS_FOR_ROOM",
-									{ room: `station.${station._id}` },
-									this
-								),
-								room: `song.${station.currentSong.songId}`
-							});
-							if (!station.paused) {
-								NotificationsModule.runJob("SCHEDULE", {
-									name: `stations.nextSong?id=${station._id}`,
-									time: station.currentSong.duration * 1000,
-									station
+						WSModule.runJob("GET_SOCKETS_FOR_ROOM", { room: `station.${station._id}` }).then(sockets => {
+							if (station.currentSong !== null && station.currentSong.songId !== undefined) {
+								WSModule.runJob("SOCKETS_JOIN_SONG_ROOM", {
+									sockets,
+									room: `song.${station.currentSong.songId}`
+								});
+								if (!station.paused) {
+									NotificationsModule.runJob("SCHEDULE", {
+										name: `stations.nextSong?id=${station._id}`,
+										time: station.currentSong.duration * 1000,
+										station
+									});
+								}
+							} else {
+								WSModule.runJob("SOCKETS_LEAVE_SONG_ROOMS", {
+									sockets
 								});
 							}
-						} else {
-							WSModule.runJob(
-								"SOCKETS_LEAVE_SONG_ROOMS",
-								{
-									sockets: await WSModule.runJob(
-										"GET_SOCKETS_FOR_ROOM",
-										{ room: `station.${station._id}` },
-										this
-									)
-								},
-								this
-							).then(() => {});
-						}
+						});
 
 						resolve({ station });
 					}