From 64fe39559e4050c1ac637620da56b55af11a5d41 Mon Sep 17 00:00:00 2001 From: Dyktus Date: Tue, 18 Dec 2018 09:06:48 +0100 Subject: [PATCH] Introduce recursive param to turn off recursively checking status pages --- src/Jsend/ServiceStatusResponse.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Jsend/ServiceStatusResponse.php b/src/Jsend/ServiceStatusResponse.php index 0e85092..559ad91 100644 --- a/src/Jsend/ServiceStatusResponse.php +++ b/src/Jsend/ServiceStatusResponse.php @@ -5,6 +5,7 @@ /* * @author Lukasz Nowak */ + 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));