enklare-development / healthcheck-helper
一个简单的类工具,用于帮助创建具有子系统检查的统一健康检查
0.0.5
2021-07-08 13:14 UTC
Requires
- php: ^7.2 || ^8.0
- nesbot/carbon: ^2.35
Requires (Dev)
- phpunit/phpunit: ^9.2
README
一个简单的类工具,用于帮助创建具有子系统检查的统一健康检查
安装
composer require enklare-development/healthcheck-helper
使用
Laravel使用示例
<?php
namespace App\Http\Controllers;
use \Enklare\Health\HealthCheck;
use \Enklare\Health\BasicHealthCheck;
class HealthController
{
/**
* Just nice to have in an API health department
**/
public function ping()
{
return response(null, 204);
}
/**
* Status healthcheck function
**/
public function status()
{
$check = new HealthCheck('my-awesome-service', "1.0.0");
$check->addCheck($this->_checkDatabase());
$check->addCheck($this->_checkRedis());
return response()->json($check, 200);
}
private function _checkDatabase()
{
$check = new BasicHealthCheck('database');
return SomeCoolHelper::isDatabaseReady() ? $check->passed(): $check->failed();
}
private function _checkRedis()
{
$check = new BasicHealthCheck('redis');
return SomeCoolHelper::isRedisReady() ? $check->passed(): $check->failed();
}
}
开发
composer install
安装依赖,然后编写代码
测试
composer test
测试并修复问题!