-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from delyriand/feature/fallback-elasticsearch…
…-failed Fallback on sylius taxon renderer if ES is down
- Loading branch information
Showing
10 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Disable the ElasticsearchChecker | ||
|
||
The plugin now checks if the Elasticsearch server is running before each search. | ||
|
||
If you want to disable this feature, you can do it by adding the following configuration: | ||
|
||
```yaml | ||
services: | ||
monsieurbiz.search.checker.elasticsearch_checker: | ||
class: MonsieurBiz\SyliusSearchPlugin\Checker\FakeElasticsearchChecker | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Search plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSearchPlugin\Checker; | ||
|
||
use JoliCode\Elastically\Factory; | ||
|
||
class ElasticsearchChecker implements ElasticsearchCheckerInterface | ||
{ | ||
private ?bool $isAvailable = null; | ||
|
||
public function check(): bool | ||
{ | ||
if (null === $this->isAvailable) { | ||
$client = (new Factory())->buildClient(); | ||
|
||
// Check client response | ||
try { | ||
$client->getStatus()->getResponse(); | ||
} catch (\Exception $e) { | ||
$this->isAvailable = false; | ||
|
||
return $this->isAvailable; | ||
} | ||
|
||
$this->isAvailable = true; | ||
} | ||
|
||
return $this->isAvailable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Search plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSearchPlugin\Checker; | ||
|
||
interface ElasticsearchCheckerInterface | ||
{ | ||
public function check(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Search plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSearchPlugin\Checker; | ||
|
||
class FakeElasticsearchChecker implements ElasticsearchCheckerInterface | ||
{ | ||
public function check(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Search plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusSearchPlugin\Routing; | ||
|
||
use Exception; | ||
use MonsieurBiz\SyliusSearchPlugin\Checker\ElasticsearchCheckerInterface; | ||
use Symfony\Component\Routing\RequestContext as BaseRequestContext; | ||
|
||
class RequestContext extends BaseRequestContext | ||
{ | ||
private BaseRequestContext $decorated; | ||
|
||
private ElasticsearchCheckerInterface $elasticsearchChecker; | ||
|
||
public function __construct( | ||
BaseRequestContext $decorated, | ||
ElasticsearchCheckerInterface $elasticsearchChecker | ||
) { | ||
parent::__construct( | ||
$decorated->getBaseUrl(), | ||
$decorated->getMethod(), | ||
$decorated->getHost(), | ||
$decorated->getScheme(), | ||
$decorated->getHttpPort(), | ||
$decorated->getHttpsPort(), | ||
$decorated->getPathInfo(), | ||
$decorated->getQueryString() | ||
); | ||
$this->decorated = $decorated; | ||
$this->elasticsearchChecker = $elasticsearchChecker; | ||
} | ||
|
||
public function checkElasticsearch(): bool | ||
{ | ||
return $this->elasticsearchChecker->check(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* | ||
* @return mixed | ||
*/ | ||
public function __call(string $name, array $arguments) | ||
{ | ||
$callback = [$this->decorated, $name]; | ||
if (\is_callable($callback)) { | ||
return \call_user_func($callback, $arguments); | ||
} | ||
|
||
throw new Exception(sprintf('Method %s not found for class "%s"', $name, \get_class($this->decorated))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters