Skip to content

Commit

Permalink
Introduce recursive param to turn off recursively checking status pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyktus committed Dec 18, 2018
1 parent 4472c09 commit 64fe395
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Jsend/ServiceStatusResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/*
* @author Lukasz Nowak <[email protected]>
*/

use Assertis\Http\Client\ClientInterface;
use Assertis\Http\Request\Request;
use Symfony\Component\HttpFoundation\Response as Status;
Expand Down Expand Up @@ -66,7 +67,8 @@ public function __construct(
array $services = [],
array $settings = [],
array $config = []
) {
)
{
$this->status = $status;
$this->environment = $environment;
$this->name = $name;
Expand Down Expand Up @@ -112,8 +114,10 @@ public static function checkServices(
array $servicesClients,
&$status,
?array $whoAsks = [],
?array $headers = []
): array {
?array $headers = [],
?int $recursive = 1
): array
{
$servicesStatus = [];
foreach ($servicesClients as $serviceName => $serviceClient) {
$serviceName = $serviceClient->getName();
Expand All @@ -122,15 +126,15 @@ public static function checkServices(
$servicesStatus[$serviceName] = !empty($serviceStatus[$serviceName]) ? $serviceStatus[$serviceName] : StatusEnum::SUCCESS;
continue;
}
$serviceStatusResult = ServiceStatusResponse::getServiceStatus($serviceClient, $whoAsks, $headers);
$serviceStatusResult = ServiceStatusResponse::getServiceStatus($serviceClient, $whoAsks, $headers, $recursive);
$data = $serviceStatusResult->getResponseBody();
if($data['status'] !== StatusEnum::SUCCESS) {
if ($data['status'] !== StatusEnum::SUCCESS) {
$status = StatusEnum::ERROR;
}
$servicesStatus[$serviceName] = $data['status'];
foreach ($data['data']['services'] as $key => $serviceStatus) {
$servicesStatus[$key] = $serviceStatus;
if($serviceStatus !== StatusEnum::SUCCESS) {
if ($serviceStatus !== StatusEnum::SUCCESS) {
$status = StatusEnum::ERROR;
}
}
Expand All @@ -148,10 +152,14 @@ public static function checkServices(
public static function getServiceStatus(
ClientInterface $client,
?array $serviceName = [],
?array $headers = []
): ServiceStatusResponse {
$query = [];
if(!empty($serviceName[0])) {
?array $headers = [],
?int $recursive = 1
): ServiceStatusResponse
{
$query = [
'recursive' => $recursive
];
if (!empty($serviceName[0])) {
$query['questioning'] = $serviceName[0];
}
$response = $client->send(new Request(self::STATUS_ENDPOINT, '', $query, Request::GET, $headers));
Expand Down

0 comments on commit 64fe395

Please sign in to comment.