From 8948631454e28fc1fb6e953389f645a3090ad1f1 Mon Sep 17 00:00:00 2001 From: jjstyle Date: Mon, 15 Dec 2025 14:30:22 +0900 Subject: [PATCH] =?UTF-8?q?worker=20=EC=99=80=20=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Commands/NaverWorker.php | 50 ++++++++++++++++++++++++++++++ app/Config/Routes.php | 13 ++++++++ app/Config/Routes/Api.php | 10 ++++++ app/Controllers/KisoController.php | 29 +++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 app/Commands/NaverWorker.php create mode 100644 app/Config/Routes/Api.php create mode 100644 app/Controllers/KisoController.php diff --git a/app/Commands/NaverWorker.php b/app/Commands/NaverWorker.php new file mode 100644 index 0000000..7f2490b --- /dev/null +++ b/app/Commands/NaverWorker.php @@ -0,0 +1,50 @@ +connect('redis', 6379); + + CLI::write('Worker started...'); + + while (true) { + // 큐에서 데이터 꺼내기 (blocking pop) + $item = $redis->brPop(['naver:queue'], 5); + if ($item) { + $payload = json_decode($item[1], true); + $this->process($payload); + } + } + } + + private function process($payload) + { + $articleNum = $payload['articleNumbr']; + $requestType = $payload['reqeustType']; + + if (in_array($requestType, ['REG','MOD'])) { + $client = \Config\Services::curlrequest(); + $url = "https://네이버CP/kiso/center/verification-article/{$articleNum}"; + + try { + $response = $client->get($url); + CLI::write("Processed {$requestType} for {$articleNum}: " . $response->getStatusCode()); + } catch (\Exception $e) { + CLI::error("Error processing {$articleNum}: " . $e->getMessage()); + } + } else { + CLI::write("Skipping {$requestType} for {$articleNum}"); + } + } +} diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 61fdffd..57cc04a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -62,3 +62,16 @@ $routes->post('/manage/dupl_phone/savePhone', 'Manage\Phone::savePhone'); // 전 $routes->get('/manage/loginlog/getLogList', 'Manage\LoginLog::getLogList'); // 로그 목록 조회 $routes->get('/manage/loginlog/excel', 'Manage\LoginLog::excel'); // 엑셀다운로드 + + +/* + * -------------------------------------------------------------------- + * Additional Routing + * -------------------------------------------------------------------- + * + * 이 영역에서 다른 라우트 파일을 로드할 수 있습니다. + */ + +if (is_file($filepath = APPPATH . 'Config/Routes/Api.php')) { + require $filepath; +} \ No newline at end of file diff --git a/app/Config/Routes/Api.php b/app/Config/Routes/Api.php new file mode 100644 index 0000000..bac8a3d --- /dev/null +++ b/app/Config/Routes/Api.php @@ -0,0 +1,10 @@ +group('kiso', function(RouteCollection $routes) { + $routes->get('api/vrfcReq', 'KisoController::vrfcReq'); +}); \ No newline at end of file diff --git a/app/Controllers/KisoController.php b/app/Controllers/KisoController.php new file mode 100644 index 0000000..71d1ffb --- /dev/null +++ b/app/Controllers/KisoController.php @@ -0,0 +1,29 @@ +request->getJSON(true); + + $articleNum = $data['articleNumbr'] ?? null; + $requestType = $data['reqeustType'] ?? null; + + if (!$articleNum || !$requestType) { + return $this->response->setStatusCode(ResponseInterface::HTTP_BAD_REQUEST) + ->setJSON(['error' => 'Invalid request']); + } + + // Redis 연결 + $redis = new \Redis(); + $redis->connect('redis', 6379); + + // 큐에 push + $redis->lPush('naver:queue', json_encode($data)); + + return $this->response->setJSON(['status' => 'queued']); + } +}