로그 생성이 안되어 테스트 및 수정본

This commit is contained in:
2026-03-20 09:33:30 +09:00
parent 80cb9451d2
commit bb07396abf
12 changed files with 205 additions and 23 deletions

View File

@@ -17,6 +17,9 @@ class NaverWorker extends BaseCommand
// DB 객체를 담을 변수 선언
protected $db;
protected $redisHost;
protected $redisPort;
protected $redisDatabase;
public function run(array $params)
{
@@ -29,13 +32,13 @@ class NaverWorker extends BaseCommand
$redis = new \Redis();
try {
// 두 가지 환경 변수 형식 지원 (REDIS_HOST 또는 redis.default.host)
$redisHost = getenv('REDIS_HOST') ?: (getenv('redis.default.host') ?: '127.0.0.1');
$redisPort = getenv('REDIS_PORT') ?: (getenv('redis.default.port') ?: 6379);
$redisDatabase = getenv('REDIS_DATABASE') ?: (getenv('redis.default.database') ?: 9);
$this->redisHost = getenv('REDIS_HOST') ?: (getenv('redis.default.host') ?: '127.0.0.1');
$this->redisPort = getenv('REDIS_PORT') ?: (getenv('redis.default.port') ?: 6379);
$this->redisDatabase = getenv('REDIS_DATABASE') ?: (getenv('redis.default.database') ?: 9);
$redis->connect($redisHost, (int)$redisPort);
$redis->select((int)$redisDatabase);
CLI::write(CLI::color('🟢 Naver Worker running... (Redis: ' . $redisHost . ':' . $redisPort . ' DB:' . $redisDatabase . ')', 'green'));
$redis->connect($this->redisHost, (int)$this->redisPort);
$redis->select((int)$this->redisDatabase);
CLI::write(CLI::color('🟢 Naver Worker running... (Redis: ' . $this->redisHost . ':' . $this->redisPort . ' DB:' . $this->redisDatabase . ')', 'green'));
} catch (\Exception $e) {
CLI::error("Redis 연결 불가: " . $e->getMessage());
return;
@@ -45,7 +48,37 @@ class NaverWorker extends BaseCommand
while (true) {
$result = $redis->brPop(['naver:raw_queue'], 30);
// Redis brPop with retry logic
$maxRetries = 3;
$retryCount = 0;
$result = null;
while ($retryCount < $maxRetries) {
try {
$result = $redis->brPop(['naver:raw_queue'], 30);
break; // 성공하면 루프 탈출
} catch (\RedisException $e) {
$retryCount++;
CLI::write(CLI::color("⚠️ Redis error (attempt {$retryCount}/{$maxRetries}): " . $e->getMessage(), 'yellow'));
if ($retryCount >= $maxRetries) {
CLI::error("❌ Redis reconnection failed after {$maxRetries} attempts");
break;
}
// Redis 재연결 시도
try {
CLI::write(CLI::color('🔄 Reconnecting to Redis...', 'yellow'));
$redis->close();
$redis->connect($this->redisHost, (int)$this->redisPort);
$redis->select((int)$this->redisDatabase);
CLI::write(CLI::color('✅ Redis reconnected', 'green'));
} catch (\Exception $reconnectError) {
CLI::error("Redis reconnection error: " . $reconnectError->getMessage());
sleep(2); // 재연결 실패 시 잠시 대기
}
}
}
if (!$result) {
// 데이터가 없어서 타임아웃 난 경우.