Files
ABSDEV/Modules/Enterprise/Console/HealthCheckCommand.php
T
2026-07-24 14:59:44 +01:00

29 lines
1.0 KiB
PHP

<?php
namespace Modules\Enterprise\Console;
use Illuminate\Console\Command;
use Modules\Enterprise\Models\HealthRun;
use Modules\Enterprise\Services\SystemHealthService;
final class HealthCheckCommand extends Command
{
protected $signature = 'enterprise:health {--json}';
protected $description = 'Run enterprise platform health checks.';
public function handle(SystemHealthService $service): int
{
$result = $service->run();
HealthRun::create(['status' => $result['status'], 'results' => $result, 'ran_at' => now()]);
if ($this->option('json')) {
$this->line(json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} else {
$this->table(['Check', 'Status', 'Message'], collect($result['checks'])->map(fn (array $check) => [$check['name'], $check['status'], $check['message']])->all());
$this->line('Overall: '.$result['status']);
}
return $result['status'] === 'failed' ? self::FAILURE : self::SUCCESS;
}
}