Skip to content

Commit

Permalink
remove last batch time. handlers are auto-flushed when idle
Browse files Browse the repository at this point in the history
  • Loading branch information
benwalch committed Apr 3, 2024
1 parent 8948d47 commit 6f14d80
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
25 changes: 0 additions & 25 deletions src/Queue/MessageHandler/ProcessResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use DynamicSearchBundle\Logger\LoggerInterface;
use DynamicSearchBundle\Queue\Message\ProcessResourceMessage;
use DynamicSearchBundle\Runner\ResourceRunnerInterface;
use Pimcore\Model\Tool\TmpStore;
use Symfony\Component\Messenger\Handler\Acknowledger;
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
use Symfony\Component\Messenger\Handler\BatchHandlerTrait;
Expand All @@ -29,9 +28,6 @@ public function __invoke(ProcessResourceMessage $message, ?Acknowledger $ack)

private function process(array $jobs): void
{

TmpStore::set('dynamic_search_processor__last_batch', time());

$groupedResourceMetas = [];

/**
Expand Down Expand Up @@ -75,27 +71,6 @@ private function process(array $jobs): void
}
}

private function shouldFlush(): bool
{
if ($this->getBatchSize() <= count($this->jobs)) {
return true;
}
$lastRunEntry = TmpStore::get('dynamic_search_processor__last_batch');
if (!$lastRunEntry instanceof TmpStore) {
TmpStore::set('dynamic_search_processor__last_batch', time());
return false;
}
$lastRun = (int)$lastRunEntry->getData();
$now = time();
$shouldFlush = $lastRun + $this->getBatchMaxAge() <= $now;
return $shouldFlush;
}

private function getBatchMaxAge(): int
{
return 60;
}

private function getBatchSize(): int
{
return 50;
Expand Down
24 changes: 0 additions & 24 deletions src/Queue/MessageHandler/QueuedResourcesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use DynamicSearchBundle\Queue\Message\ProcessResourceMessage;
use DynamicSearchBundle\Queue\Message\QueueResourceMessage;
use Pimcore\Model\Element;
use Pimcore\Model\Tool\TmpStore;
use Symfony\Component\Messenger\Handler\Acknowledger;
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
use Symfony\Component\Messenger\Handler\BatchHandlerTrait;
Expand All @@ -35,8 +34,6 @@ public function __invoke(QueueResourceMessage $message, ?Acknowledger $ack = nul

private function process(array $jobs): void
{
TmpStore::set('dynamic_search_queue__last_batch', time());

/**
* @var QueueResourceMessage $message
* @var Acknowledger $ack
Expand Down Expand Up @@ -107,27 +104,6 @@ protected function generateResourceMeta(string $contextName, string $dispatchTyp
return $normalizedResourceStack;
}

private function shouldFlush(): bool
{
if ($this->getBatchSize() <= count($this->jobs)) {
return true;
}
$lastRunEntry = TmpStore::get('dynamic_search_queue__last_batch');
if (!$lastRunEntry instanceof TmpStore) {
TmpStore::set('dynamic_search_queue__last_batch', time());
return false;
}
$lastRun = (int)$lastRunEntry->getData();
$now = time();
$shouldFlush = $lastRun + $this->getBatchMaxAge() <= $now;
return $shouldFlush;
}

private function getBatchMaxAge(): int
{
return 30;
}

private function getBatchSize(): int
{
return 50;
Expand Down

0 comments on commit 6f14d80

Please sign in to comment.