refactor(redis, discovery, cache): streamline configuration defaults, logging, and error handling
- Remove default values for `RedisConfig` constructor to enforce explicit configuration. - Enhance `FileStreamProcessor` logging by adding `LogContext` with exception details. - Replace `humanReadable` method call with `toHumanReadable` in `DiscoveryCompletedEvent`. - Remove redundant error trace logging in `CacheInitializer` for cleaner fallback handling.
This commit is contained in:
@@ -68,7 +68,6 @@ final readonly class CacheInitializer
|
||||
// Fallback to file cache if Redis is not available
|
||||
|
||||
error_log('Redis not available, falling back to file cache: ' . $e->getMessage());
|
||||
error_log(print_r($e->getTrace(), true));
|
||||
|
||||
$redisCache = new GeneralCache(new FileCache(), $serializer, $compression);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,14 @@ final readonly class DiscoveryCompletedEvent
|
||||
public ?ScannerMetrics $metrics,
|
||||
public ScanType $scanType,
|
||||
public Timestamp $timestamp
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'files_scanned' => $this->filesScanned,
|
||||
'duration_seconds' => $this->duration->toSeconds(),
|
||||
'duration_human' => $this->duration->humanReadable(),
|
||||
'duration_human' => $this->duration->toHumanReadable(),
|
||||
'metrics' => $this->metrics?->toArray(),
|
||||
'scan_type' => $this->scanType->value,
|
||||
'timestamp' => $this->timestamp->toFloat(),
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Framework\Filesystem\ValueObjects\FilePath;
|
||||
use App\Framework\Filesystem\FileScanner;
|
||||
use App\Framework\Filesystem\ValueObjects\FilePattern;
|
||||
use App\Framework\Logging\Logger;
|
||||
use App\Framework\Logging\ValueObjects\LogContext;
|
||||
use Generator;
|
||||
|
||||
/**
|
||||
@@ -68,7 +69,8 @@ final readonly class FileStreamProcessor
|
||||
} catch (\Throwable $e) {
|
||||
// Only log errors, not every processed file
|
||||
$this->logger?->warning(
|
||||
"Failed to process file {$file->getPath()->toString()}: {$e->getMessage()} in FileStreamProcessor"
|
||||
"Failed to process file {$file->getPath()->toString()}: {$e->getMessage()} in FileStreamProcessor",
|
||||
LogContext::withException($e)
|
||||
);
|
||||
} finally {
|
||||
// Always cleanup after processing a file
|
||||
|
||||
@@ -13,9 +13,9 @@ use App\Framework\Config\EnvKey;
|
||||
final readonly class RedisConfig
|
||||
{
|
||||
private function __construct(
|
||||
public string $host = 'redis',
|
||||
public int $port = 6379,
|
||||
public ?string $password = null,
|
||||
public string $host,
|
||||
public int $port,
|
||||
public string $password,
|
||||
public int $database = 0,
|
||||
public float $timeout = 1.0,
|
||||
public float $readWriteTimeout = 1.0,
|
||||
@@ -31,9 +31,9 @@ final readonly class RedisConfig
|
||||
public static function fromEnvironment(Environment $env): self
|
||||
{
|
||||
return new self(
|
||||
host: $env->get(EnvKey::REDIS_HOST, 'redis'),
|
||||
port: $env->getInt(EnvKey::REDIS_PORT, 6379),
|
||||
password: $env->get(EnvKey::REDIS_PASSWORD, null),
|
||||
host: $env->get(EnvKey::REDIS_HOST),
|
||||
port: $env->getInt(EnvKey::REDIS_PORT),
|
||||
password: $env->get(EnvKey::REDIS_PASSWORD),
|
||||
database: 0,
|
||||
timeout: 1.0,
|
||||
readWriteTimeout: 1.0,
|
||||
|
||||
Reference in New Issue
Block a user