You've already forked Php-Template
feat: enhance healthcheck functionality with Redis and database checks
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m54s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m59s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m56s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 1m56s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m34s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m13s
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m54s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m59s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m56s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 1m56s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m34s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m13s
This commit is contained in:
@@ -77,7 +77,7 @@ services:
|
||||
WORKERS: 1
|
||||
DEBUG: 1
|
||||
REDIS_HOST: redis
|
||||
POSTGRES_HOST: postgres
|
||||
DB_HOST: postgres
|
||||
JWT_SIGNING_KEY: a-string-secret-at-least-256-bits-long
|
||||
|
||||
redis:
|
||||
|
||||
@@ -4,18 +4,41 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Controllers;
|
||||
|
||||
use Illuminate\Database\PostgresConnection;
|
||||
use Nyholm\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Siteworxpro\App\Http\JsonResponseFactory;
|
||||
use Siteworxpro\App\Models\Model;
|
||||
use Siteworxpro\App\Services\Facades\Redis;
|
||||
use Siteworxpro\HttpStatus\CodesEnum;
|
||||
|
||||
class HealthcheckController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function get(ServerRequest $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
/** @var PostgresConnection $conn */
|
||||
$conn = Model::getConnectionResolver()->connection();
|
||||
$conn->getPdo()->exec('SELECT 1');
|
||||
|
||||
$response = Redis::ping();
|
||||
if ($response->getPayload() !== 'PONG') {
|
||||
throw new \Exception('Redis ping failed');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return JsonResponseFactory::createJsonResponse(
|
||||
[
|
||||
'status_code' => CodesEnum::SERVICE_UNAVAILABLE->value,
|
||||
'message' => 'Healthcheck Failed',
|
||||
'error' => $e->getMessage(),
|
||||
],
|
||||
CodesEnum::SERVICE_UNAVAILABLE
|
||||
);
|
||||
}
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(
|
||||
['status_code' => 200, 'message' => 'Healthcheck OK']
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ use Siteworxpro\App\Services\Facade;
|
||||
* @method static Status|null set(string $key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
|
||||
* @method static array keys(string $pattern)
|
||||
* @method static int del(string $key)
|
||||
* @method static Status ping()
|
||||
*/
|
||||
class Redis extends Facade
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user