Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
@@ -4,15 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Database\HealthCheck;
|
||||
|
||||
use App\Framework\Core\ValueObjects\Duration;
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Exception\DatabaseException;
|
||||
use App\Framework\DateTime\SystemTimer;
|
||||
use App\Framework\DateTime\Timer;
|
||||
|
||||
final readonly class ConnectionHealthChecker
|
||||
{
|
||||
public function __construct(
|
||||
private Timer $timer,
|
||||
private int $timeoutSeconds = 5,
|
||||
private array $customQueries = []
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt einen einfachen Health Check aus
|
||||
@@ -40,6 +44,7 @@ final readonly class ConnectionHealthChecker
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$responseTime = (microtime(true) - $startTime) * 1000;
|
||||
|
||||
return HealthCheckResult::error($e, $responseTime);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +64,7 @@ final readonly class ConnectionHealthChecker
|
||||
}
|
||||
|
||||
// Kurz warten vor nächstem Versuch
|
||||
usleep(100000); // 100ms
|
||||
$this->timer->sleep(Duration::fromMilliseconds(100));
|
||||
}
|
||||
|
||||
return HealthCheckResult::timeout($this->timeoutSeconds * 1000);
|
||||
@@ -76,7 +81,7 @@ final readonly class ConnectionHealthChecker
|
||||
try {
|
||||
// 1. Basis Health Check
|
||||
$basicResult = $this->checkHealth($connection);
|
||||
if (!$basicResult->isHealthy) {
|
||||
if (! $basicResult->isHealthy) {
|
||||
return $basicResult;
|
||||
}
|
||||
|
||||
@@ -87,7 +92,7 @@ final readonly class ConnectionHealthChecker
|
||||
$additionalData['pdo_status'] = $pdoStatus;
|
||||
|
||||
// 3. Custom Queries ausführen
|
||||
if (!empty($this->customQueries)) {
|
||||
if (! empty($this->customQueries)) {
|
||||
$customResults = $this->executeCustomQueries($connection);
|
||||
$additionalData['custom_queries'] = $customResults;
|
||||
}
|
||||
@@ -106,6 +111,7 @@ final readonly class ConnectionHealthChecker
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$responseTime = (microtime(true) - $startTime) * 1000;
|
||||
|
||||
return HealthCheckResult::error($e, $responseTime)->withAdditionalData('partial_data', $additionalData);
|
||||
}
|
||||
}
|
||||
@@ -120,6 +126,7 @@ final readonly class ConnectionHealthChecker
|
||||
|
||||
// Prüfe ob die PDO-Verbindung noch aktiv ist
|
||||
$stmt = $pdo->query('SELECT 1');
|
||||
|
||||
return $stmt !== false;
|
||||
|
||||
} catch (\Throwable) {
|
||||
@@ -216,18 +223,18 @@ final readonly class ConnectionHealthChecker
|
||||
/**
|
||||
* Factory-Methoden für verschiedene Health Check-Konfigurationen
|
||||
*/
|
||||
public static function quick(int $timeoutSeconds = 2): self
|
||||
public static function quick(?Timer $timer = null, int $timeoutSeconds = 2): self
|
||||
{
|
||||
return new self($timeoutSeconds);
|
||||
return new self($timer ?? new SystemTimer(), $timeoutSeconds);
|
||||
}
|
||||
|
||||
public static function detailed(int $timeoutSeconds = 10, array $customQueries = []): self
|
||||
public static function detailed(?Timer $timer = null, int $timeoutSeconds = 10, array $customQueries = []): self
|
||||
{
|
||||
return new self($timeoutSeconds, $customQueries);
|
||||
return new self($timer ?? new SystemTimer(), $timeoutSeconds, $customQueries);
|
||||
}
|
||||
|
||||
public static function withCustomQueries(array $customQueries, int $timeoutSeconds = 5): self
|
||||
public static function withCustomQueries(array $customQueries, ?Timer $timer = null, int $timeoutSeconds = 5): self
|
||||
{
|
||||
return new self($timeoutSeconds, $customQueries);
|
||||
return new self($timer ?? new SystemTimer(), $timeoutSeconds, $customQueries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ final readonly class HealthCheckResult
|
||||
public ?string $message = null,
|
||||
public ?\Throwable $exception = null,
|
||||
public array $additionalData = []
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
|
||||
@@ -9,11 +9,13 @@ use App\Framework\Database\ConnectionInterface;
|
||||
final class HealthCheckScheduler
|
||||
{
|
||||
private array $healthChecks = [];
|
||||
|
||||
private array $lastResults = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly ConnectionHealthChecker $healthChecker
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registriert einen Health Check
|
||||
@@ -62,7 +64,7 @@ final class HealthCheckScheduler
|
||||
{
|
||||
$config = $config ?? $this->healthChecks[$name] ?? null;
|
||||
|
||||
if (!$config) {
|
||||
if (! $config) {
|
||||
return HealthCheckResult::error(
|
||||
new \InvalidArgumentException("Health check '{$name}' not found")
|
||||
);
|
||||
@@ -101,7 +103,7 @@ final class HealthCheckScheduler
|
||||
public function areAllHealthy(): bool
|
||||
{
|
||||
foreach ($this->lastResults as $result) {
|
||||
if (!$result->isHealthy) {
|
||||
if (! $result->isHealthy) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -147,6 +149,7 @@ final class HealthCheckScheduler
|
||||
public function unregisterHealthCheck(string $name): self
|
||||
{
|
||||
unset($this->healthChecks[$name], $this->lastResults[$name]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -157,6 +160,7 @@ final class HealthCheckScheduler
|
||||
{
|
||||
$this->healthChecks = [];
|
||||
$this->lastResults = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user