From 6f14d805468fb1fa08db9dac3aedd80579386f8e Mon Sep 17 00:00:00 2001 From: Ben Walch Date: Wed, 3 Apr 2024 13:06:42 +0200 Subject: [PATCH] remove last batch time. handlers are auto-flushed when idle --- .../MessageHandler/ProcessResourceHandler.php | 25 ------------------- .../MessageHandler/QueuedResourcesHandler.php | 24 ------------------ 2 files changed, 49 deletions(-) diff --git a/src/Queue/MessageHandler/ProcessResourceHandler.php b/src/Queue/MessageHandler/ProcessResourceHandler.php index 6572dff..af697e1 100644 --- a/src/Queue/MessageHandler/ProcessResourceHandler.php +++ b/src/Queue/MessageHandler/ProcessResourceHandler.php @@ -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; @@ -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 = []; /** @@ -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; diff --git a/src/Queue/MessageHandler/QueuedResourcesHandler.php b/src/Queue/MessageHandler/QueuedResourcesHandler.php index 611383a..01b280e 100644 --- a/src/Queue/MessageHandler/QueuedResourcesHandler.php +++ b/src/Queue/MessageHandler/QueuedResourcesHandler.php @@ -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; @@ -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 @@ -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;