This commit is contained in:
2026-01-23 17:46:34 +09:00
parent 522b89fb9f
commit 9f511b4dba
2 changed files with 285 additions and 13 deletions

View File

@@ -15,10 +15,14 @@ class NaverWorker extends BaseCommand
protected $name = 'naver:worker';
protected $description = 'Redis에서 데이터를 꺼내 DB에 저장하고 네이버 API를 호출합니다.';
// DB 객체를 담을 변수 선언
protected $db;
public function run(array $params)
{
helper('log'); // 여기서 로드 완료!
$this->db = \Config\Database::connect();
$logModel = model(NaverWorkerLogModel::class);
$naverService = new \App\Services\NaverService(); // 서비스 생성
@@ -35,6 +39,17 @@ class NaverWorker extends BaseCommand
while (true) {
// 1. DB 연결 상태 체크 (더 견고하게)
try {
if ($this->db->connID === false || !@$this->db->connID->ping()) {
$this->db->reconnect();
CLI::write(CLI::color('🔄 Database reconnected.', 'yellow'));
}
} catch (\Throwable $e) {
$this->db->reconnect();
}
$result = $redis->brPop(['naver:raw_queue'], 30);
if (!$result) {
@@ -81,6 +96,9 @@ class NaverWorker extends BaseCommand
$redis->lPush('naver:failed_queue', $rawData);
helper('log');
write_custom_log("FAILED_DATA | Error: " . $e->getMessage(), 'ERROR', 'failed');
// 루프 과부하 방지 (연속 에러 시)
sleep(1);
}
}
}