diff --git a/app/Jobs/Searcher.php b/app/Jobs/Searcher.php index 2d7a48b3c8425628cba02c3a0983df0873076e5e..b3df969bd25e1ab7f036910561bf21be3f62f7cc 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 549322ed99938b0b6bde999703611df0ac962af0..f22a90f7afe93c3ee301cfce6110f92f25119745 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, ], ],