38 lines
1.7 KiB
PHP
38 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use LogicException;
|
|
use Throwable;
|
|
|
|
/** Read-only composition of existing technical inspections; never runs recovery or repairs. */
|
|
class OperationalHealth
|
|
{
|
|
/** @return array<string,mixed> */
|
|
public function inspect(int $documentLimit = 1000): array
|
|
{
|
|
abort_unless(app()->runningInConsole() && ! auth()->check() && ! request()->hasSession(), 403);
|
|
if ($documentLimit < 1 || $documentLimit > 10000) {
|
|
throw new LogicException('Limite fora do intervalo permitido.');
|
|
}
|
|
$checks = [];
|
|
$startedAt = now()->toIso8601String();
|
|
foreach (['replenishment' => fn () => app(ReplenishmentQueue::class)->health(),
|
|
'receipt_documents' => fn () => app(ReceiptDocumentHealth::class)->inspect($documentLimit)] as $key => $read) {
|
|
try {
|
|
$result = $read();
|
|
$complete = $result['complete'] ?? true;
|
|
$checks[$key] = ['status' => ! $complete ? 'incomplete' : ($result['ok'] ? 'passed' : 'attention'), 'result' => $result];
|
|
} catch (Throwable $error) {
|
|
report($error);
|
|
$checks[$key] = ['status' => 'unavailable', 'result' => ['checked_at' => now()->toIso8601String(), 'ok' => false, 'complete' => false, 'reasons' => ['unavailable']]];
|
|
}
|
|
}
|
|
|
|
return ['schema_version' => 1, 'started_at' => $startedAt, 'checked_at' => now()->toIso8601String(),
|
|
'ok' => collect($checks)->every(fn ($check) => $check['status'] === 'passed'),
|
|
'complete' => collect($checks)->every(fn ($check) => in_array($check['status'], ['passed', 'attention'], true)),
|
|
'checks' => $checks];
|
|
}
|
|
}
|