소스 검색

crawlerPlanSave retry

wangyunpeng 1 주 전
부모
커밋
4e5335f506

+ 17 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/aigc/AIGCCrawlerPlanSaveService.java

@@ -2,8 +2,8 @@ package com.tzld.longarticle.recommend.server.remote.aigc;
 
 import cn.hutool.core.io.resource.ResourceUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
 import com.tzld.longarticle.recommend.server.model.vo.IdNameVO;
+import com.tzld.longarticle.recommend.server.util.HttpClientFactory;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpEntity;
 import org.apache.http.StatusLine;
@@ -22,9 +22,22 @@ import java.util.Objects;
 @Slf4j
 public class AIGCCrawlerPlanSaveService {
 
-    private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
+    private final CloseableHttpClient client =
+            HttpClientFactory.create(10000, 120000, 200, 200, 0, 10000);
 
     public IdNameVO<String> createArticleUrlPlan(String planName, List<String> contentList, String tag, Integer crawlerMode) {
+        int retryTimes = 2;
+        while (retryTimes > 0) {
+            IdNameVO<String> result = post(planName, contentList, tag, crawlerMode);
+            if (Objects.nonNull(result)) {
+                return result;
+            }
+            retryTimes--;
+        }
+        return new IdNameVO<>();
+    }
+
+    public IdNameVO<String> post(String planName, List<String> contentList, String tag, Integer crawlerMode) {
         IdNameVO<String> result = new IdNameVO<>();
         if (contentList == null || contentList.isEmpty()) {
             return null;
@@ -67,9 +80,10 @@ public class AIGCCrawlerPlanSaveService {
                     }
                 }
             }
+            return result;
         } catch (Exception e) {
             log.error("createArticleUrlPlan error", e);
         }
-        return result;
+        return null;
     }
 }