Introduce ProviderHealthChecker which probes each configured provider via AutowireIterator. Wire it into GraphController so /health returns detailed per-provider status and responds 503 when any provider is in a degraded state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
965 B
PHP
40 lines
965 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
|
|
|
|
final class ProviderHealthChecker
|
|
{
|
|
public function __construct(
|
|
#[AutowireIterator('app.provider')]
|
|
private readonly iterable $providers,
|
|
) {}
|
|
|
|
/**
|
|
* @return array{status: string, providers: array<string, array<string, string>>}
|
|
*/
|
|
public function check(): array
|
|
{
|
|
$statuses = [];
|
|
$hasError = false;
|
|
|
|
/** @var ProviderInterface $provider */
|
|
foreach ($this->providers as $provider) {
|
|
$status = $provider->probe();
|
|
$statuses[$status->name] = $status->toArray();
|
|
|
|
if ($status->status === ProviderStatusType::Error) {
|
|
$hasError = true;
|
|
}
|
|
}
|
|
|
|
return [
|
|
'status' => $hasError ? 'degraded' : 'ok',
|
|
'providers' => $statuses,
|
|
];
|
|
}
|
|
}
|