Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
2e4b5308
Commit
2e4b5308
authored
Feb 19, 2020
by
Dominik Hebeler
Browse files
using cache connection more
parent
f80e27c2
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/RequestFetcher.php
View file @
2e4b5308
...
...
@@ -56,13 +56,14 @@ class RequestFetcher extends Command
try
{
$blocking
=
false
;
$redis
=
Redis
::
connection
(
"cache"
);
while
(
$this
->
shouldRun
)
{
$status
=
curl_multi_exec
(
$this
->
multicurl
,
$active
);
$currentJob
=
null
;
if
(
!
$blocking
)
{
$currentJob
=
R
edis
::
lpop
(
\
App\MetaGer
::
FETCHQUEUE_KEY
);
$currentJob
=
$r
edis
->
lpop
(
\
App\MetaGer
::
FETCHQUEUE_KEY
);
}
else
{
$currentJob
=
R
edis
::
blpop
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
1
);
$currentJob
=
$r
edis
->
blpop
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
1
);
if
(
!
empty
(
$currentJob
))
{
$currentJob
=
$currentJob
[
1
];
}
...
...
@@ -97,11 +98,8 @@ class RequestFetcher extends Command
$body
=
\
curl_multi_getcontent
(
$info
[
"handle"
]);
}
Redis
::
pipeline
(
function
(
$pipe
)
use
(
$resulthash
,
$body
,
$cacheDurationMinutes
)
{
$pipe
->
set
(
$resulthash
,
$body
);
$pipe
->
expire
(
$resulthash
,
60
);
Cache
::
put
(
$resulthash
,
$body
,
$cacheDurationMinutes
*
60
);
});
Cache
::
put
(
$resulthash
,
$body
,
$cacheDurationMinutes
*
60
);
\
curl_multi_remove_handle
(
$this
->
multicurl
,
$info
[
"handle"
]);
}
if
(
!
$active
&&
!
$answerRead
)
{
...
...
@@ -110,6 +108,8 @@ class RequestFetcher extends Command
usleep
(
50
*
1000
);
}
}
}
catch
(
\
Exception
$e
)
{
Log
::
error
(
$e
->
getMessage
());
}
finally
{
curl_multi_close
(
$this
->
multicurl
);
}
...
...
app/MetaGer.php
View file @
2e4b5308
...
...
@@ -6,7 +6,6 @@ use App;
use
Cache
;
use
Carbon
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
use
Jenssegers\Agent\Agent
;
use
LaravelLocalization
;
use
Log
;
...
...
@@ -854,7 +853,7 @@ class MetaGer
while
(
sizeof
(
$enginesToWaitFor
)
>
0
||
(
$forceTimeout
!==
null
&&
(
microtime
(
true
)
-
$timeStart
)
<
$forceTimeout
))
{
foreach
(
$enginesToWaitFor
as
$index
=>
$engine
)
{
if
(
Redis
::
get
(
$engine
->
hash
)
!==
null
)
{
if
(
Cache
::
get
(
$engine
->
hash
)
!==
null
)
{
$answered
[]
=
$engine
;
unset
(
$enginesToWaitFor
[
$index
]);
break
;
...
...
app/Models/Quicktips/Quicktips.php
View file @
2e4b5308
...
...
@@ -46,7 +46,7 @@ class Quicktips
$mission
=
json_encode
(
$mission
);
Redis
::
rpush
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
$mission
);
Redis
::
connection
(
'cache'
)
->
rpush
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
$mission
);
}
}
...
...
app/Models/Searchengine.php
View file @
2e4b5308
...
...
@@ -3,6 +3,7 @@
namespace
App\Models
;
use
App\MetaGer
;
use
Cache
;
use
Illuminate\Support\Facades\Redis
;
abstract
class
Searchengine
...
...
@@ -147,7 +148,7 @@ abstract class Searchengine
// Submit this mission to the corresponding Redis Queue
// Since each Searcher is dedicated to one specific search engine
// each Searcher has it's own queue lying under the redis key <name>.queue
Redis
::
rpush
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
$mission
);
Redis
::
connection
(
'cache'
)
->
rpush
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
$mission
);
if
(
!
empty
(
$timings
))
{
$timings
[
"startSearch"
][
$this
->
name
][
"pushed job"
]
=
microtime
(
true
)
-
$timings
[
"starttime"
];
}
...
...
@@ -193,7 +194,7 @@ abstract class Searchengine
$body
=
""
;
}
}
else
{
$body
=
Redis
::
get
(
$this
->
hash
);
$body
=
Cache
::
get
(
$this
->
hash
);
}
if
(
$body
!==
null
)
{
...
...
routes/web.php
View file @
2e4b5308
...
...
@@ -21,7 +21,9 @@ Route::group(
/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
Route
::
get
(
'/'
,
'StartpageController@loadStartPage'
);
Route
::
get
(
'sand'
,
function
()
{
abort
(
500
,
"test"
);
});
Route
::
get
(
'asso'
,
function
()
{
return
view
(
'assoziator.asso'
)
->
with
(
'title'
,
trans
(
'titles.asso'
))
...
...
Dominik Hebeler
@dominik
mentioned in commit
fb92a6d1
·
Feb 20, 2020
mentioned in commit
fb92a6d1
mentioned in commit fb92a6d116c43a63cee2ef3159dfab372fa9c6b5
Toggle commit list
Dominik Hebeler
@dominik
mentioned in merge request
!1533 (merged)
·
Feb 20, 2020
mentioned in merge request
!1533 (merged)
mentioned in merge request !1533
Toggle commit list
Dominik Hebeler
@dominik
mentioned in commit
8d87af86
·
Feb 22, 2020
mentioned in commit
8d87af86
mentioned in commit 8d87af86efab950d5e21dc0e27702ed94323e2c7
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment