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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user