Skip to content

Commit

Permalink
minor improvement, debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
rliebi committed Oct 6, 2024
1 parent 66900af commit 0f36ed9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Messenger/Handler/RefreshElementInIndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Valantic\ElasticaBridgeBundle\Messenger\Handler;

use Pimcore\Model\Element\AbstractElement;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Valantic\ElasticaBridgeBundle\Messenger\Message\RefreshElementInIndex;
use Valantic\ElasticaBridgeBundle\Repository\IndexRepository;
use Valantic\ElasticaBridgeBundle\Service\LockService;
Expand All @@ -21,6 +22,7 @@ public function __construct(
private readonly PropagateChanges $propagateChanges,
private readonly LockService $lockService,
private readonly IndexRepository $indexRepository,
private readonly ConsoleOutputInterface $consoleOutput,
) {}

public function __invoke(RefreshElementInIndex $message): void
Expand All @@ -32,6 +34,8 @@ public function __invoke(RefreshElementInIndex $message): void
PropagateChanges::stopPropagation();
}

$this->consoleOutput->writeln(sprintf('Refreshing element %s in index %s', $element->getId(), $index->getName()), ConsoleOutputInterface::VERBOSITY_VERBOSE);

if ($index->usesBlueGreenIndices() && !$this->lockService->getIndexingLock($index)->acquire()) {
$this->propagateChanges->handleIndex($element, $index, $index->getBlueGreenInactiveElasticaIndex());
}
Expand Down
14 changes: 7 additions & 7 deletions src/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ public function allMessagesProcessed(string $indexName, int $attempt = 0): bool
return $currentCount === 0;
}

if ($attempt > 2) {
$actualMessageCount = $this->getActualMessageCount($indexName);
$this->consoleOutput->writeln(sprintf('%s: %d attempts reached. Getting data from db. (%d => %d)', $indexName, $attempt, $currentCount, $actualMessageCount), ConsoleOutputInterface::VERBOSITY_VERBOSE);
$currentCount = $actualMessageCount;
if ($currentCount > 0 && $attempt < 3) {
return false;
}

if ($currentCount > 0) {
return false;
$actualMessageCount = $this->getActualMessageCount($indexName);

if ($attempt > 2) {
$this->consoleOutput->writeln(sprintf('%s: %d attempts reached. Getting data from db. (%d => %d)', $indexName, $attempt, $currentCount, $actualMessageCount), ConsoleOutputInterface::VERBOSITY_VERBOSE);
}

if ($this->getActualMessageCount($indexName) > 0) {
if ($actualMessageCount > 0) {
return false;
}

Expand Down

0 comments on commit 0f36ed9

Please sign in to comment.