Auto-scale NP timeout if not set in environment vars.

This commit is contained in:
Buster Neece 2023-01-22 19:16:20 -06:00
parent 9b0a0b159f
commit 133ab260dc
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
3 changed files with 22 additions and 4 deletions

View File

@ -64,6 +64,17 @@ final class NowPlayingCommand extends CommandAbstract
$timeout = (int)$input->getOption('timeout');
$delay = $this->environment->getNowPlayingDelayTime();
// If delay is default value, auto-scale it with station count.
if ($delay < 1) {
$numStations = $this->stationRepo->getActiveCount();
$delay = (int)min(
4 + round($numStations / 5),
20
);
}
$this->logger->pushProcessor(
function (LogRecord $record) use ($station) {
$record->extra['station'] = [
@ -76,7 +87,7 @@ final class NowPlayingCommand extends CommandAbstract
$this->logger->info('Starting Now Playing sync task.');
$this->loop($station, $timeout, $this->environment->getNowPlayingDelayTime());
$this->loop($station, $timeout, $delay);
$this->logger->info('Now Playing sync task complete.');
$this->logger->popProcessor();

View File

@ -39,8 +39,15 @@ final class StationRepository extends Repository
: $this->repository->findOneBy(['short_name' => $identifier]);
}
/**
*/
public function getActiveCount(): int
{
return $this->em->createQuery(
<<<'DQL'
SELECT COUNT(s.id) FROM App\Entity\Station s WHERE s.is_enabled = 1
DQL
)->getSingleScalarResult();
}
public function fetchAll(): mixed
{
return $this->em->createQuery(

View File

@ -83,7 +83,7 @@ final class Environment
self::SYNC_SHORT_EXECUTION_TIME => 600,
self::SYNC_LONG_EXECUTION_TIME => 1800,
self::NOW_PLAYING_DELAY_TIME => 5,
self::NOW_PLAYING_DELAY_TIME => 0,
self::PROFILING_EXTENSION_ENABLED => 0,
self::PROFILING_EXTENSION_ALWAYS_ON => 0,