Skip to content

Commit

Permalink
refactor: indexUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Apr 10, 2024
1 parent 98400b5 commit 085b3b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Service/Indexer/BackgroundIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public function index(): IndexerStatus
return $this->indexer->index();
}

/**
* @param array<string> $paths
*/
public function update(array $paths): IndexerStatus
{
return $this->indexer->update($paths);
}

/**
* @throws ExceptionInterface
*/
Expand Down
20 changes: 14 additions & 6 deletions src/Service/Indexer/InternalResourceIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function __construct(
private readonly IndexingAborter $aborter,
private readonly IndexerConfigurationLoader $configLoader,
private readonly string $source,
private readonly LoggerInterface $logger = new NullLogger(),
private readonly LockFactory $lockFactory = new LockFactory(
new SemaphoreStore()
),
private readonly LoggerInterface $logger = new NullLogger()
) {
}

Expand Down Expand Up @@ -116,20 +116,28 @@ public function abort(): void
*/
public function index(): IndexerStatus
{
$lock = $this->lockFactory->createLock('indexer.' . $this->source);
$lock = $this->lockFactory->createLock(
'indexer.' . $this->getBaseIndex()
);
if (!$lock->acquire()) {
$this->logger->notice(
'Indexer with source "' . $this->source . '" is already running'
);
$this->logger->notice('Indexer is already running', [
'index' => $this->getBaseIndex()
]);
return $this->progressHandler->getStatus();
}
$param = $this->getIndexerParameter();

$this->logger->info('Start indexing', [
'index' => $this->getBaseIndex(),
'chunkSize' => $param->chunkSize,
'cleanupThreshold' => $param->cleanupThreshold,
]);
try {
$paths = $this->finder->findAll();
$this->deleteErrorProtocol($this->getBaseIndex());
$total = count($paths);
$this->progressHandler->start($total);

$param = $this->getIndexerParameter();
$this->indexResources($param, $this->finder->findAll());
} finally {
$lock->release();
Expand Down

0 comments on commit 085b3b0

Please sign in to comment.