From 18b1e88577c171c7b4e86a3cd3eaa29a09cf075b Mon Sep 17 00:00:00 2001 From: Buster Neece Date: Tue, 31 Jan 2023 13:39:01 -0600 Subject: [PATCH] Avoid initial "Station Offline" state after a restart. --- .../Liquidsoap/Command/FeedbackCommand.php | 6 ++---- src/Radio/Configuration.php | 20 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php b/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php index 26958a5c0..69c5ee5a1 100644 --- a/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php +++ b/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php @@ -29,6 +29,7 @@ final class FeedbackCommand extends AbstractCommand // Process extra metadata sent by Liquidsoap (if it exists). try { $historyRow = $this->getSongHistory($station, $payload); + $this->em->persist($historyRow); $this->historyRepo->changeCurrentSong($station, $historyRow); @@ -99,10 +100,7 @@ final class FeedbackCommand extends AbstractCommand $this->queueRepo->trackPlayed($station, $sq); - $sh = Entity\SongHistory::fromQueue($sq); - $this->em->persist($sh); - - return $sh; + return Entity\SongHistory::fromQueue($sq); } $history = new Entity\SongHistory($station, $media); diff --git a/src/Radio/Configuration.php b/src/Radio/Configuration.php index ce2b26721..fa4dc4ec3 100644 --- a/src/Radio/Configuration.php +++ b/src/Radio/Configuration.php @@ -209,6 +209,8 @@ final class Configuration $frontend?->write($station); $backend?->write($station); + $this->markAsStarted($station); + // Reload Supervisord and process groups if ($reloadSupervisor) { $affected_groups = $this->reloadSupervisor(); @@ -227,8 +229,6 @@ final class Configuration } } } - - $this->markAsStarted($station); } private function getSupervisorConfigFile(Station $station): string @@ -241,22 +241,24 @@ final class Configuration Station $station, bool $reloadSupervisor = true ): void { - $supervisorConfigFile = $this->getSupervisorConfigFile($station); - @unlink($supervisorConfigFile); - if ($reloadSupervisor) { - $this->stopForStation($station); - } - $station->setHasStarted(false); $station->setNeedsRestart(false); $station->clearCache(); $this->em->persist($station); $this->em->flush(); + + $supervisorConfigFile = $this->getSupervisorConfigFile($station); + @unlink($supervisorConfigFile); + if ($reloadSupervisor) { + $this->stopForStation($station); + } } private function stopForStation(Station $station): void { + $this->markAsStarted($station); + $station_group = 'station_' . $station->getId(); $affected_groups = $this->reloadSupervisor(); @@ -266,8 +268,6 @@ final class Configuration } catch (SupervisorException) { } } - - $this->markAsStarted($station); } private function markAsStarted(Station $station): void