Files
confirms/app/Commands/NaverWorker.php
2025-12-15 14:30:22 +09:00

51 lines
1.5 KiB
PHP

<?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}");
}
}
}