Commit f7762e75 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Request fetcher will now accept all pending jobs on each cycle

parent f5579908
...@@ -82,17 +82,22 @@ class RequestFetcher extends Command ...@@ -82,17 +82,22 @@ class RequestFetcher extends Command
$blocking = false; $blocking = false;
while ($this->shouldRun) { while ($this->shouldRun) {
$status = curl_multi_exec($this->multicurl, $active); $status = curl_multi_exec($this->multicurl, $active);
$currentJob = null; $currentJobs = [];
if (!$blocking) { if (!$blocking) {
$currentJob = Redis::lpop(\App\MetaGer::FETCHQUEUE_KEY); $elements = Redis::pipeline(function($redis){
$redis->lrange(\App\MetaGer::FETCHQUEUE_KEY, 0, -1);
$redis->del(\App\MetaGer::FETCHQUEUE_KEY);
});
$currentJobs = $elements[0];
} else { } else {
$currentJob = Redis::blpop(\App\MetaGer::FETCHQUEUE_KEY, 1); $currentJob = Redis::blpop(\App\MetaGer::FETCHQUEUE_KEY, 1);
if (!empty($currentJob)) { if (!empty($currentJob)) {
$currentJob = $currentJob[1]; $currentJobs[] = $currentJob[1];
} }
} }
if (!empty($currentJob)) { if (sizeof($currentJobs) > 0) {
foreach($currentJobs as $currentJob){
$currentJob = json_decode($currentJob, true); $currentJob = json_decode($currentJob, true);
$ch = $this->getCurlHandle($currentJob); $ch = $this->getCurlHandle($currentJob);
if (curl_multi_add_handle($this->multicurl, $ch) !== 0) { if (curl_multi_add_handle($this->multicurl, $ch) !== 0) {
...@@ -110,6 +115,7 @@ class RequestFetcher extends Command ...@@ -110,6 +115,7 @@ class RequestFetcher extends Command
$blocking = false; $blocking = false;
$active = true; $active = true;
} }
}
$answerRead = $this->readMultiCurl($this->multicurl); $answerRead = $this->readMultiCurl($this->multicurl);
if ($this->oldMultiCurl != null) { if ($this->oldMultiCurl != null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment