Browse Source

自定义sleep 时间

supeng 6 hours ago
parent
commit
af226b4521

+ 2 - 1
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/service/impl/GeminiGenerateContentAction.java

@@ -80,6 +80,7 @@ public class GeminiGenerateContentAction implements Action {
                 log.error("geminiGenerateContentAction error param = {}", JSON.toJSONString(geminiParam), e);
                 throw new RuntimeException("geminiGenerateContentAction request error", e);
             }
-        }, RETRY_TIMES, "geminiGenerateContentAction", i -> (long) (Math.pow(5, i) * 1000));
+        }, RETRY_TIMES, "geminiGenerateContentAction", RetryUtil::retryInterval);
     }
+
 }

+ 28 - 1
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/util/RetryUtil.java

@@ -41,12 +41,13 @@ public class RetryUtil {
 
     /**
      * 重试
+     *
      * @param action
      * @param maxRetries
      * @param actionName
      * @param retryIntervalProvider 毫秒
-     * @return
      * @param <T>
+     * @return
      */
     public static <T> T executeWithRetry(Supplier<T> action, Integer maxRetries, String actionName, Function<Integer, Long> retryIntervalProvider) {
         for (int i = 1; i <= maxRetries; i++) {
@@ -74,4 +75,30 @@ public class RetryUtil {
         }
         return null;
     }
+
+    /**
+     * @param i 第i次
+     * @return 毫秒
+     */
+    public static long retryInterval(int i) {
+        if (i == 1) {
+            return 10 * 1000L;
+        }
+        if (i == 2) {
+            return 30 * 1000L;
+        }
+        if (i == 3) {
+            return 60 * 1000L;
+        }
+        if (i == 4) {
+            return 3 * 60 * 1000L;
+        }
+        if (i == 5) {
+            return 5 * 60 * 1000L;
+        }
+        if (i == 6) {
+            return 10 * 60 * 1000L;
+        }
+        return 0L;
+    }
 }