Auto-scale NP timeout if not set in environment vars.
This commit is contained in:
parent
9b0a0b159f
commit
133ab260dc
|
@ -64,6 +64,17 @@ final class NowPlayingCommand extends CommandAbstract
|
||||||
|
|
||||||
$timeout = (int)$input->getOption('timeout');
|
$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(
|
$this->logger->pushProcessor(
|
||||||
function (LogRecord $record) use ($station) {
|
function (LogRecord $record) use ($station) {
|
||||||
$record->extra['station'] = [
|
$record->extra['station'] = [
|
||||||
|
@ -76,7 +87,7 @@ final class NowPlayingCommand extends CommandAbstract
|
||||||
|
|
||||||
$this->logger->info('Starting Now Playing sync task.');
|
$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->info('Now Playing sync task complete.');
|
||||||
$this->logger->popProcessor();
|
$this->logger->popProcessor();
|
||||||
|
|
|
@ -39,8 +39,15 @@ final class StationRepository extends Repository
|
||||||
: $this->repository->findOneBy(['short_name' => $identifier]);
|
: $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
|
public function fetchAll(): mixed
|
||||||
{
|
{
|
||||||
return $this->em->createQuery(
|
return $this->em->createQuery(
|
||||||
|
|
|
@ -83,7 +83,7 @@ final class Environment
|
||||||
|
|
||||||
self::SYNC_SHORT_EXECUTION_TIME => 600,
|
self::SYNC_SHORT_EXECUTION_TIME => 600,
|
||||||
self::SYNC_LONG_EXECUTION_TIME => 1800,
|
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_ENABLED => 0,
|
||||||
self::PROFILING_EXTENSION_ALWAYS_ON => 0,
|
self::PROFILING_EXTENSION_ALWAYS_ON => 0,
|
||||||
|
|
Loading…
Reference in New Issue