#5623 -- Make Now Playing delay customizable.

This commit is contained in:
Buster Neece 2023-01-17 02:34:00 -06:00
parent b48cb5e49a
commit 2c0456a5a5
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
3 changed files with 29 additions and 9 deletions

View File

@ -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);
}
}
}

View File

@ -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]
);
}
/**

View File

@ -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,