diff --git a/src/Console/Command/Sync/NowPlayingCommand.php b/src/Console/Command/Sync/NowPlayingCommand.php index 0f882bd8f..28ad5a922 100644 --- a/src/Console/Command/Sync/NowPlayingCommand.php +++ b/src/Console/Command/Sync/NowPlayingCommand.php @@ -8,6 +8,7 @@ use App\Console\Command\CommandAbstract; use App\Doctrine\ReloadableEntityManagerInterface; use App\Entity\Repository\StationRepository; use App\Entity\Station; +use App\Environment; use App\Sync\NowPlaying\Task\BuildQueueTask; use App\Sync\NowPlaying\Task\NowPlayingTask; use Monolog\Logger; @@ -32,6 +33,7 @@ final class NowPlayingCommand extends CommandAbstract private readonly BuildQueueTask $buildQueueTask, private readonly NowPlayingTask $nowPlayingTask, private readonly Logger $logger, + private readonly Environment $environment ) { parent::__construct(); } @@ -74,7 +76,7 @@ final class NowPlayingCommand extends CommandAbstract $this->logger->info('Starting Now Playing sync task.'); - $this->loop($station, $timeout); + $this->loop($station, $timeout, $this->environment->getNowPlayingDelayTime()); $this->logger->info('Now Playing sync task complete.'); $this->logger->popProcessor(); @@ -82,7 +84,7 @@ final class NowPlayingCommand extends CommandAbstract return 0; } - private function loop(Station $station, int $timeout): void + private function loop(Station $station, int $timeout, int $delay): void { $threshold = time() + $timeout; @@ -109,7 +111,7 @@ final class NowPlayingCommand extends CommandAbstract $this->em->clear(); gc_collect_cycles(); - usleep(5000000); + sleep($delay); } } } diff --git a/src/Environment.php b/src/Environment.php index 05168f528..287c839bb 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -43,6 +43,7 @@ final class Environment public const SYNC_SHORT_EXECUTION_TIME = 'SYNC_SHORT_EXECUTION_TIME'; public const SYNC_LONG_EXECUTION_TIME = 'SYNC_LONG_EXECUTION_TIME'; + public const NOW_PLAYING_DELAY_TIME = 'NOW_PLAYING_DELAY_TIME'; public const LOG_LEVEL = 'LOG_LEVEL'; public const SHOW_DETAILED_ERRORS = 'SHOW_DETAILED_ERRORS'; @@ -82,6 +83,7 @@ final class Environment self::SYNC_SHORT_EXECUTION_TIME => 600, self::SYNC_LONG_EXECUTION_TIME => 1800, + self::NOW_PLAYING_DELAY_TIME => 5, self::PROFILING_EXTENSION_ENABLED => 0, self::PROFILING_EXTENSION_ALWAYS_ON => 0, @@ -247,12 +249,23 @@ final class Environment public function getSyncShortExecutionTime(): int { - return (int)($this->data[self::SYNC_SHORT_EXECUTION_TIME] ?? 600); + return (int)( + $this->data[self::SYNC_SHORT_EXECUTION_TIME] ?? $this->defaults[self::SYNC_SHORT_EXECUTION_TIME] + ); } public function getSyncLongExecutionTime(): int { - return (int)($this->data[self::SYNC_LONG_EXECUTION_TIME] ?? 1800); + return (int)( + $this->data[self::SYNC_LONG_EXECUTION_TIME] ?? $this->defaults[self::SYNC_LONG_EXECUTION_TIME] + ); + } + + public function getNowPlayingDelayTime(): int + { + return (int)( + $this->data[self::NOW_PLAYING_DELAY_TIME] ?? $this->defaults[self::NOW_PLAYING_DELAY_TIME] + ); } /** diff --git a/src/Installer/EnvFiles/AzuraCastEnvFile.php b/src/Installer/EnvFiles/AzuraCastEnvFile.php index f78fcc5cd..37d3c742d 100644 --- a/src/Installer/EnvFiles/AzuraCastEnvFile.php +++ b/src/Installer/EnvFiles/AzuraCastEnvFile.php @@ -183,22 +183,27 @@ final class AzuraCastEnvFile extends AbstractEnvFile 'default' => '128M', ], 'PHP_MAX_EXECUTION_TIME' => [ - 'name' => __('PHP Script Maximum Execution Time'), - 'description' => __('(in seconds)'), + 'name' => __('PHP Script Maximum Execution Time (Seconds)'), 'default' => 30, ], Environment::SYNC_SHORT_EXECUTION_TIME => [ - 'name' => __('Short Sync Task Execution Time'), + 'name' => __('Short Sync Task Execution Time (Seconds)'), 'description' => __( 'The maximum execution time (and lock timeout) for the 15-second, 1-minute and 5-minute synchronization tasks.' ), ], Environment::SYNC_LONG_EXECUTION_TIME => [ - 'name' => __('Long Sync Task Execution Time'), + 'name' => __('Long Sync Task Execution Time (Seconds)'), 'description' => __( 'The maximum execution time (and lock timeout) for the 1-hour synchronization task.', ), ], + Environment::NOW_PLAYING_DELAY_TIME => [ + 'name' => __('Now Playing Delay Time (Seconds)'), + 'description' => __( + 'The delay between Now Playing checks for every station. Decrease for more frequent checks at the expense of performance; increase for less frequent checks but better performance (for large installations).' + ), + ], 'PHP_FPM_MAX_CHILDREN' => [ 'name' => __('Maximum PHP-FPM Worker Processes'), 'default' => 5,