From c95f66f4b81e81df9432c0c6d306ad22e3f5e587 Mon Sep 17 00:00:00 2001
From: hcong <1050828145@qq.com>
Date: 星期一, 02 十二月 2024 11:41:09 +0800
Subject: [PATCH] socket以及后台任务状态实时刷新

---
 src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt b/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt
index c8f23f6..730c3a6 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/common/executor/BackgroundTaskCtrl.kt
@@ -1,6 +1,7 @@
 package cn.flightfeather.supervision.common.executor
 
 import cn.flightfeather.supervision.common.exception.BizException
+import cn.flightfeather.supervision.common.utils.SendSocketMessageUtil
 import org.springframework.stereotype.Component
 import java.util.concurrent.ConcurrentHashMap
 import java.util.concurrent.Executors
@@ -62,7 +63,12 @@
             }
         } else {
             task.ready()
-            task.future = executorService.submit { task.execute() }
+            task.future = executorService.submit {
+                task.execute()
+                println(task.taskStatus.runTime)
+                SendSocketMessageUtil.sendBgTaskMessage(task.taskStatus)
+            }
+            SendSocketMessageUtil.sendBgTaskMessage(task.taskStatus)
             return task
         }
     }
@@ -111,11 +117,13 @@
         return if (id != null) {
             val task = taskMap[id] ?: throw BizException("鏃犳硶鍏抽棴浠诲姟锛屼换鍔${id}]涓嶅瓨鍦�")
             task.shutdown()
+            SendSocketMessageUtil.sendBgTaskMessage(task.taskStatus)
             listOf(task.taskStatus)
         } else {
             val res = mutableListOf<BgTaskStatus?>()
             taskMap.forEach { (t, u) ->
                 u.shutdown()
+                SendSocketMessageUtil.sendBgTaskMessage(u.taskStatus)
                 res.add(u.taskStatus)
             }
             res.sortedBy { it?.createTime }

--
Gitblit v1.9.3