Explorar el Código

videoMultiCoverTitle retry

wangyunpeng hace 1 semana
padre
commit
8b54009c60

+ 29 - 19
api-module/src/main/java/com/tzld/piaoquan/api/component/ManagerApiService.java

@@ -77,15 +77,20 @@ public class ManagerApiService {
     public JSONArray videoMultiCoverListV2(Long videoId) {
         String url = managerApiHost + "/video/multiCover/listV2";
         JSONObject res = null;
-        try {
-            JSONObject param = new JSONObject();
-            param.put("videoId", videoId);
-            param.put("range", "2h");
-            String post = httpPoolClient.post(url, param.toJSONString());
-            res = JSONObject.parseObject(post);
-        } catch (Exception e) {
-            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
-                    videoId, "2h", e);
+        int retry = 0;
+        while (retry < 3) {
+            try {
+                JSONObject param = new JSONObject();
+                param.put("videoId", videoId);
+                param.put("range", "2h");
+                String post = httpPoolClient.post(url, param.toJSONString());
+                res = JSONObject.parseObject(post);
+                break;
+            } catch (Exception e) {
+                log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
+                        videoId, "2h", e);
+                retry++;
+            }
         }
         if (Objects.isNull(res)) {
             throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED);
@@ -102,21 +107,26 @@ public class ManagerApiService {
     public JSONArray videoMultiTitleListV2(Long videoId) {
         String url = managerApiHost + "/video/multiTitleV2/listV2";
         JSONObject res = null;
-        try {
-            JSONObject param = new JSONObject();
-            param.put("videoId", videoId);
-            param.put("range", "4h");
-            String post = httpPoolClient.post(url, param.toJSONString());
-            res = JSONObject.parseObject(post);
-        } catch (Exception e) {
-            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
-                    videoId, "4h", e);
+        int retry = 0;
+        while (retry < 3) {
+            try {
+                JSONObject param = new JSONObject();
+                param.put("videoId", videoId);
+                param.put("range", "4h");
+                String post = httpPoolClient.post(url, param.toJSONString());
+                res = JSONObject.parseObject(post);
+                break;
+            } catch (Exception e) {
+                log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
+                        videoId, "4h", e);
+                retry++;
+            }
         }
         if (Objects.isNull(res)) {
             throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED);
         }
         if (res.getInteger("code") != 0) {
-            log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
+            log.error("ManagerApiService videoMultiTitleListV2 error, videoId={} range={} res={}",
                     videoId, "4h", res);
             throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getCode(),
                     ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getMsg() + "," + res.getString("msg"));