Ver código fonte

fix 定时两分钟拉取未执行完成任务

zwhui 2 anos atrás
pai
commit
bf63b47ab3

+ 3 - 0
midjourney/src/main/java/com/yhlxj/service/midjourney/MidjourneyService.java

@@ -36,4 +36,7 @@ public interface MidjourneyService {
     void notifyHook(String conversation) throws Exception;
 
     MidjourneyUser getUser(String userToken);
+
+    void syscConversation();
+
 }

+ 17 - 0
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -818,4 +818,21 @@ public class MidjourneyServiceImpl implements MidjourneyService {
          */
         private Integer height;
     }
+
+
+    @Override
+    public void syscConversation() {
+        List<MidjourneyUserConversation> midjourneyUserConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
+                .eq(MidjourneyUserConversation::getStatus, "IN_PROGRESS").orderByAsc(MidjourneyUserConversation::getId).last("limit 10"));
+        midjourneyUserConversations.forEach(dbConversation -> {
+            try {
+                JSONArray jsonArray = listByIds(dbConversation.getMode(), List.of(dbConversation.getTaskId()));
+                for (Object json : jsonArray) {
+                    notifyHook(Jsons.toJson(json));
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
 }

+ 6 - 0
midjourney/src/main/java/com/yhlxj/web/mirror/MidjourneyController.java

@@ -28,6 +28,7 @@ import com.yhlxj.service.midjourney.MidjourneyService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.Cookie;
@@ -464,4 +465,9 @@ public class MidjourneyController {
         }
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
+
+    @Scheduled(cron = "0 0/2 * * * ?")
+    public void syscConversation() {
+        midjourneyService.syscConversation();
+    }
 }