作者 ZhengBing He

fetchV5 同步V5.0工单项目 加上重试次数

@@ -60,7 +60,29 @@ class FetchTicketProjects extends Command @@ -60,7 +60,29 @@ class FetchTicketProjects extends Command
60 $postids = []; 60 $postids = [];
61 61
62 while (true) { 62 while (true) {
63 - $response = Http::get('https://www.quanqiusou.cn/extend_api/webs/globalso_all.php?page=' . $page); 63 + try {
  64 + $maxRetries = 3;
  65 + $retryCount = 0;
  66 +
  67 + while ($retryCount < $maxRetries) {
  68 + try {
  69 + $response = Http::get('https://www.quanqiusou.cn/extend_api/webs/globalso_all.php?page=' . $page);
  70 + break; // 如果请求成功,跳出重试循环
  71 + } catch (\Exception $e) {
  72 + $retryCount++;
  73 + if ($retryCount >= $maxRetries) {
  74 + // 如果达到最大重试次数,抛出异常
  75 + throw $e;
  76 + }
  77 + // 等待一段时间再重试
  78 + sleep(2);
  79 + }
  80 + }
  81 + }catch (\Exception $e){
  82 + echo now() . " | ERROR | " . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
  83 + break;
  84 + }
  85 +
64 if ($response->status() == 200) { 86 if ($response->status() == 200) {
65 $resp_json = $response->json(); 87 $resp_json = $response->json();
66 $items = $resp_json['data'] ?? []; 88 $items = $resp_json['data'] ?? [];