diff --git a/README.md b/README.md index c434c2b..ac9254a 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ ___ ## $checker->liveness() -Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that allows you to check if your application is *OK* without checking any kind of integration. +Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that allows you to check if your application is _OK_ without checking any kind of integration. ```json { @@ -91,7 +91,7 @@ Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that "version": "v1.0.0", // the main status checks, will return true when all integrations does not fail "status": true, - // + // ISO 8601 date "date": "2022-06-25T11:52:56-03:00", "duration": 0.08681011199951172, "integrations": [ @@ -111,6 +111,7 @@ Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that ```sh composer require gritzkoo/php-health-checker ``` + ## Create a HTTP inteface to expose probs Once you create an instance of `Gritzkoo\HealthChecker\HealthChecker` you should create 2 routes in your application to expose `liveness` and `readiness` actions like: @@ -144,11 +145,12 @@ class HealthCheckController extends Controller return $this->checker->readiness() } } -``` +``` ___ ->route file `routes/web.php` +>route file `routes/web.php` + ```php [ [ 'name' => 'YourIntegrationA', + // is just a closure you write to test something and return + // an instance of \Gritzkoo\HealthChecker\Check 'handle' => $api1->test ], [ 'name' => 'YourIntegrationB', + // is just a closure you write to test something and return + // an instance of \Gritzkoo\HealthChecker\Check 'handle' => $api2->test ], ] diff --git a/src/HealthChecker.php b/src/HealthChecker.php index a85d739..c0a344c 100644 --- a/src/HealthChecker.php +++ b/src/HealthChecker.php @@ -37,7 +37,25 @@ public function liveness() ]; } /** - * Undocumented function + * Readiness will return a full set of informations about the + * integrations list you pass to create a instance of \Gritzkoo\HealthChecker\HealthChecker + * with aditional informations like: + * { + * "name": "My application name", + * "version": "v1.0.0", + * "status": true, + * "date": "2022-06-25T11:52:56-03:00", + * "duration": 0.08681011199951172, + * "integrations": [ + * { + * "name": "github status check", + * "status": true, + * "response_time": 0.08406686782836914, + * "url": "https://github.com/status", + * "error": null + * } + * ] + * } * * @return array */ diff --git a/tests/Providers/HealthCheckerTrait.php b/tests/Providers/HealthCheckerTrait.php index d3747f3..c51dc0b 100644 --- a/tests/Providers/HealthCheckerTrait.php +++ b/tests/Providers/HealthCheckerTrait.php @@ -52,7 +52,7 @@ function () { ]; } ], - // testing integrations + // testing integrations =============================================================== 'should run readiness with a integration' => [ function () { $conf = $this->defaultConfig; @@ -77,6 +77,43 @@ function () { ]; } ], + 'should run readiness and fail because the second integration fail' => [ + function () { + $conf = $this->defaultConfig; + $conf['integrations'] = [ + [ + 'name' => 'test 1', + 'handle' => function () { + return new Check(); + } + ], + [ + 'name' => 'test 2', + 'handle' => function () { + return new Check(['error' => 'some error']); + } + ] + ]; + $exp = $this->readinessContract; + $exp['status'] = false; + $exp['integrations'] = [ + [ + 'name' => 'test 1', + 'status' => true, + ], + [ + 'name' => 'test 2', + 'status' => false, + 'error' => 'some error' + ] + ]; + return [ + 'method' => Constants::READINESS, + 'config' => $conf, + 'expected' => $exp + ]; + } + ], 'should run readiness with a integration and validate return type' => [ function () { $conf = $this->defaultConfig; @@ -154,7 +191,7 @@ function () { ]; } ], - // error section ====================================================================== + // throw section ====================================================================== 'should throw error because construct is not an array' => [ function () { return [