worker 와 라우터 수정
This commit is contained in:
50
app/Commands/NaverWorker.php
Normal file
50
app/Commands/NaverWorker.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Commands;
|
||||||
|
|
||||||
|
use CodeIgniter\CLI\BaseCommand;
|
||||||
|
use CodeIgniter\CLI\CLI;
|
||||||
|
|
||||||
|
class NaverWorker extends BaseCommand
|
||||||
|
{
|
||||||
|
protected $group = 'Workers';
|
||||||
|
protected $name = 'naver:worker';
|
||||||
|
protected $description = 'Process Naver verification requests from Redis queue';
|
||||||
|
|
||||||
|
public function run(array $params)
|
||||||
|
{
|
||||||
|
$redis = new \Redis();
|
||||||
|
$redis->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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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/getLogList', 'Manage\LoginLog::getLogList'); // 로그 목록 조회
|
||||||
$routes->get('/manage/loginlog/excel', 'Manage\LoginLog::excel'); // 엑셀다운로드
|
$routes->get('/manage/loginlog/excel', 'Manage\LoginLog::excel'); // 엑셀다운로드
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Additional Routing
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* 이 영역에서 다른 라우트 파일을 로드할 수 있습니다.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (is_file($filepath = APPPATH . 'Config/Routes/Api.php')) {
|
||||||
|
require $filepath;
|
||||||
|
}
|
||||||
10
app/Config/Routes/Api.php
Normal file
10
app/Config/Routes/Api.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Routes 변수는 반드시 use 해야 합니다.
|
||||||
|
use CodeIgniter\Router\RouteCollection;
|
||||||
|
|
||||||
|
/** @var RouteCollection $routes */
|
||||||
|
|
||||||
|
$routes->group('kiso', function(RouteCollection $routes) {
|
||||||
|
$routes->get('api/vrfcReq', 'KisoController::vrfcReq');
|
||||||
|
});
|
||||||
29
app/Controllers/KisoController.php
Normal file
29
app/Controllers/KisoController.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
|
||||||
|
class KisoController extends BaseController
|
||||||
|
{
|
||||||
|
public function vrfcReq()
|
||||||
|
{
|
||||||
|
$data = $this->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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user