From 51622b6579f8dcdef072f5c3c2729b0929646836 Mon Sep 17 00:00:00 2001 From: Dominik Pfennig <dominik@suma-ev.de> Date: Thu, 22 Feb 2018 14:01:14 +0100 Subject: [PATCH] =?UTF-8?q?Fehler=20in=20den=20Fetchern=20behoben,=20der?= =?UTF-8?q?=20erh=C3=B6hte=20Ladezeiten=20verursacht=20haben=20k=C3=B6nnte?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/Searcher.php | 9 ++++++++- config/queue.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Searcher.php b/app/Jobs/Searcher.php index 2d7a48b3c..b3df969bd 100644 --- a/app/Jobs/Searcher.php +++ b/app/Jobs/Searcher.php @@ -15,7 +15,11 @@ class Searcher implements ShouldQueue use InteractsWithQueue, Queueable, SerializesModels; protected $name, $ch, $pid, $counter, $lastTime, $connectionInfo; + # Each Searcher will shutdown after a specified time(s) or number of requests protected $MAX_REQUESTS = 100; + # This value should always be below the retry_after value in config/queue.php + protected $MAX_TIME = 240; + protected $startTime = null; protected $importantEngines = array("Fastbot", "overture", "overtureAds"); protected $recheck; @@ -35,6 +39,7 @@ class Searcher implements ShouldQueue $this->name = $name; $this->pid = getmypid(); $this->recheck = false; + $this->startTime = microtime(true); // Submit this worker to the Redis System Redis::expire($this->name, 5); } @@ -91,7 +96,9 @@ class Searcher implements ShouldQueue // In sync mode every Searcher may only retrieve one result because it would block // the execution of the remaining code otherwise: - if(getenv("QUEUE_DRIVER") === "sync" || $this->counter > $this->MAX_REQUESTS){ + if(getenv("QUEUE_DRIVER") === "sync" + || $this->counter > $this->MAX_REQUESTS + || (microtime(true)-$this->startTime) > $this->MAX_TIME){ break; } } diff --git a/config/queue.php b/config/queue.php index 549322ed9..f22a90f7a 100644 --- a/config/queue.php +++ b/config/queue.php @@ -45,7 +45,7 @@ return [ 'driver' => 'beanstalkd', 'host' => 'localhost', 'queue' => 'default', - 'retry_after' => 90, + 'retry_after' => 90, ], 'sqs' => [ @@ -61,7 +61,7 @@ return [ 'driver' => 'redis', 'connection' => 'default', 'queue' => 'default', - 'retry_after' => 90, + 'retry_after' => 300, ], ], -- GitLab