cfmgrv4 init...2

This commit is contained in:
최준흠 2024-10-12 09:38:32 +09:00
parent b72373d323
commit 4b914ccb21
7 changed files with 50 additions and 48 deletions

View File

@ -59,12 +59,10 @@ class Cloudflare extends BaseController
foreach ($auths as $auth) {
$accounts += $this->account_process($auth);
}
log_message("debug", "\n-------------총 Accounts:" . count($accounts) . "--------------------\n");
$zones = [];
foreach ($accounts as $key => $account) {
$zones += $this->zone_process($account);
}
log_message("debug", "\n-------------총 Zones:" . count($zones) . "--------------------\n");
foreach ($zones as $key => $zone) {
$this->record_process($zone);
}

View File

@ -51,24 +51,25 @@ abstract class Cloudflare extends CommonLibrary
private function reload_page(string $uri, int $page, int $per_page = 20): mixed
{
$query = [
'name' => '',
'status' => '',
'order' => 'name',
'direction' => 'asc',
'page' => $page,
'per_page' => $per_page,
'match' => 'all',
'cache_buster' => time(), // 캐시 무효화를 위한 파라미터 추가
'cache_buster' => uniqid(), // 매 요청마다 고유한 값 사용
];
// 요청 헤더에 캐시 제어 추가
$headers = [
'Cache-Control' => 'no-cache',
'Pragma' => 'no-cache',
];
// log_message("debug", var_export($query, true));
$response = $this->getMySocket()->get($uri, $query);
$response = $this->getMySocket()->get($uri, $query, $headers);
$cf = json_decode($response->getBody());
if (!$cf->success) {
$message = __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
log_message("error", $message);
throw new \Exception($message);
}
log_message("debug", "Page {$page} response: " . var_export($cf->result_info, true));
// log_message("debug", "Page {$page} response: " . var_export($cf->result_info, true));
return $cf;
}
final protected function reload_procedure(string $uri): array
@ -79,7 +80,9 @@ abstract class Cloudflare extends CommonLibrary
$per_page = $cf->result_info->per_page;
$total_page = $cf->result_info->total_pages;
$results = $cf->result;
for ($i = $page + 1; $i < $total_page; $i++) {
for ($i = $page + 1; $i <= $total_page; $i++) {
// API 제한을 고려한 지연 추가
usleep(100000); // 0.1초 대기
$cf = $this->reload_page($uri, $i, $per_page);
$results = array_merge($results, $cf->result);
log_message("debug", "현재: page[{$i}/{$total_page}] , result수[" . count($results) . "]");

View File

@ -11,7 +11,7 @@ class CloudflareSocket extends MySocket
private ?Client $_client = null;
public static int $_request = 0;
private static int $_request_max = 1000;
private static int $_request_timewait = 30;
private static int $_request_timewait = 10;
private ?AuthEntity $_auth_entity = null;
public function __construct(AuthEntity $auth_entity)
{

View File

@ -48,15 +48,15 @@ abstract class MySocket
}
public function request(string $method, $uri = '', array $options = [], array $headers = []): ResponseInterface
{
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])) {
throw new \InvalidArgumentException("{$method} => Request method must be GET, POST, PUT, PATCH, or DELETE");
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException("{$method} => Request method must be get, post, put, patch, or delete");
}
try {
$options = $this->getRequestOptions($method, $options, $headers);
log_message("debug", __FUNCTION__ .
"=> 호출 Socket URL:{$uri}\n--------------\n" .
var_export($options, true) .
"\n--------------\n");
// log_message("debug", __FUNCTION__ .
// "=> 호출 Socket URL:{$uri}\n--------------\n" .
// var_export($options, true) .
// "\n--------------\n");
$response = $this->getClient()->$method($uri, $options);
} catch (RequestException $err) {
throw ResponseException::fromRequestException($err);
@ -65,22 +65,22 @@ abstract class MySocket
}
final public function get($uri, array $options = [], array $headers = []): ResponseInterface
{
return $this->request('GET', $uri, $options, $headers);
return $this->request(__FUNCTION__, $uri, $options, $headers);
}
final public function post($uri, array $options = [], array $headers = []): ResponseInterface
{
return $this->request('POST', $uri, $options, $headers);
return $this->request(__FUNCTION__, $uri, $options, $headers);
}
final public function put($uri, array $options = [], array $headers = []): ResponseInterface
{
return $this->request('PUT', $uri, $options, $headers);
return $this->request(__FUNCTION__, $uri, $options, $headers);
}
final public function patch($uri, array $options = [], array $headers = []): ResponseInterface
{
return $this->request('PATCH', $uri, $options, $headers);
return $this->request(__FUNCTION__, $uri, $options, $headers);
}
public function delete($uri, array $options = [], array $headers = []): ResponseInterface
{
return $this->request('DELETE', $uri, $options, $headers);
return $this->request(__FUNCTION__, $uri, $options, $headers);
}
}

View File

@ -75,7 +75,8 @@ abstract class CommonModel extends Model
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
} else {
$rule = "required|numeric";
};
}
;
break;
case $this->getTitleField():
$rule = "required|string";
@ -166,7 +167,7 @@ abstract class CommonModel extends Model
if (!$this->save($entity)) {
throw new \Exception("저장오류:" . var_export($this->errors(), true));
}
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
return $entity;
} catch (\Exception $e) {
$message = sprintf(