Files
reservas/app/Http/Controllers/HealthController.php

44 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Throwable;
final class HealthController extends Controller
{
public function live(): JsonResponse
{
return response()
->json(['status' => 'ok'])
->header('Cache-Control', 'no-store');
}
public function ready(): JsonResponse
{
try {
DB::select('select 1');
$key = 'health:'.bin2hex(random_bytes(12));
Cache::put($key, 'ok', 5);
$cacheReady = Cache::pull($key) === 'ok';
if (! $cacheReady) {
throw new \RuntimeException('Cache read/write check failed.');
}
} catch (Throwable $exception) {
report($exception);
return response()
->json(['status' => 'not_ready'], 503)
->header('Cache-Control', 'no-store');
}
return response()
->json(['status' => 'ready'])
->header('Cache-Control', 'no-store');
}
}