diff --git a/lib/BackgroundJobs/IndexerJob.php b/lib/BackgroundJobs/IndexerJob.php index 8def831..f91fd0d 100644 --- a/lib/BackgroundJobs/IndexerJob.php +++ b/lib/BackgroundJobs/IndexerJob.php @@ -30,6 +30,8 @@ class IndexerJob extends TimedJob { + public const DEFAULT_MAX_INDEXING_TIME = 5 * 60; + public function __construct( ITimeFactory $time, private LoggerInterface $logger, @@ -42,7 +44,7 @@ public function __construct( private IAppConfig $appConfig, ) { parent::__construct($time); - $this->setInterval(60 * 5); + $this->setInterval($this->getMaxIndexingTime()); $this->setTimeSensitivity(self::TIME_INSENSITIVE); } @@ -111,13 +113,22 @@ protected function getBatchSize(): int { return $this->appConfig->getAppValueInt('indexing_batch_size', 100); } + protected function getMaxIndexingTime(): int { + return $this->appConfig->getAppValueInt('indexing_max_time', self::DEFAULT_MAX_INDEXING_TIME); + } + /** * @param QueueFile[] $files * @return void * @throws \RuntimeException|\ErrorException */ protected function index(array $files): void { + $maxTime = $this->getMaxIndexingTime(); + $startTime = time(); foreach ($files as $queueFile) { + if ($startTime + $maxTime < time()) { + break; + } $file = current($this->rootFolder->getById($queueFile->getFileId())); if (!$file instanceof File) { continue;