فهرست منبع

增加计算进度通知

dsx 2 سال پیش
والد
کامیت
47569ce098

+ 15 - 1
src/main/java/com/fdkankan/contro/mq/listener/BuildSceneProgressListener.java

@@ -1,5 +1,6 @@
 package com.fdkankan.contro.mq.listener;
 
+import cn.hutool.core.thread.ThreadUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.contro.mq.service.IBuildSceneProgressService;
 import com.fdkankan.contro.mq.service.impl.BuildSceneServiceImpl;
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.nio.charset.StandardCharsets;
+import java.util.concurrent.*;
 
 @Slf4j
 @Component
@@ -40,7 +42,19 @@ public class BuildSceneProgressListener{
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
         log.info("开始推送场景计算进度,队列名:{},id:{},消息体:{}", queueName, messageId, msg);
         BuildSceneCallMessage buildSceneMessage = JSONObject.parseObject(msg, BuildSceneCallMessage.class);
-        buildSceneProgressService.monitorProgress(buildSceneMessage);
+        ExecutorService executor = ThreadUtil.newSingleExecutor();
+        Future future = executor.submit(() -> {
+            buildSceneProgressService.monitorProgress(buildSceneMessage);
+        });
+        try {
+            future.get(2*24*60*60, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        } catch (TimeoutException e) {
+            e.printStackTrace();
+        }
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
         Thread.sleep(100000000);
         log.info("推送场景计算进度完成,队列名:{},id:{},消息体:{}", queueName, messageId, msg);

+ 1 - 15
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneProgressServiceImpl.java

@@ -71,8 +71,7 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
             e.printStackTrace();
         }
 
-        ExecutorService executor = ThreadUtil.newSingleExecutor();
-        Future future = executor.submit(() -> {
+
             String projectJsonPath = path.concat(File.separator).concat("project.json");
             File file = FileUtil.file(projectJsonPath);
             WatchMonitor watchMonitor = WatchMonitor.create(file);
@@ -126,7 +125,6 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
                         log.info("算法完成发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
                         HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
                         watchMonitor.interrupt();
-                        executor.shutdown();
                     } else {
                         int progress = new BigDecimal(projectJson.getDouble("progress")).multiply(new BigDecimal(100)).intValue();
                         log.info("当前进度为,progress:{}",progress);
@@ -148,7 +146,6 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
                 @Override
                 public void onDelete(WatchEvent<?> event, Path currentPath) {
                     watchMonitor.interrupt();
-                    executor.shutdown();
                 }
 
                 @Override
@@ -156,18 +153,7 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
                 }
             });
             watchMonitor.start();
-        });
-
 
-        try {
-            future.get(2*24*60*60, TimeUnit.SECONDS);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        } catch (ExecutionException e) {
-            e.printStackTrace();
-        } catch (TimeoutException e) {
-            e.printStackTrace();
-        }
 
     }