-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce recursive param to turn off recursively checking status pages
- Loading branch information
Showing
1 changed file
with
18 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -66,7 +67,8 @@ public function __construct( | |
array $services = [], | ||
array $settings = [], | ||
array $config = [] | ||
) { | ||
) | ||
{ | ||
$this->status = $status; | ||
$this->environment = $environment; | ||
$this->name = $name; | ||
|
@@ -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(); | ||
|
@@ -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; | ||
} | ||
} | ||
|
@@ -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)); | ||
|