From 7fdb6afda8dff9eadfa7add11471a18396a9fce7 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 11 三月 2025 09:17:28 +0800
Subject: [PATCH] 监控model服务状态,崩溃后重启

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/CheckIailabModelServiceTask.java |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/CheckIailabModelServiceTask.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/CheckIailabModelServiceTask.java
new file mode 100644
index 0000000..9012749
--- /dev/null
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/CheckIailabModelServiceTask.java
@@ -0,0 +1,56 @@
+package com.iailab.module.shasteel.job.task;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.iailab.framework.common.util.http.HttpUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * 监控model服务状态,崩溃后重启
+ *
+ * @author PanZhibao
+ * @Description
+ * @createTime 2025年03月11日
+ */
+@Component("checkIailabModelServiceTask")
+public class CheckIailabModelServiceTask implements ITask {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Resource
+    private RestartIailabModelServiceTask restartIailabModelServiceTask;
+
+    @Override
+    public void run(String params) {
+        logger.info("CheckIailabModelServiceTask定时任务正在执行,参数为:{}", params);
+        boolean isHealth = true;
+        try {
+            if (StringUtils.isEmpty(params)) {
+                return;
+            }
+            String url = "http://" + params + "/actuator/health";
+            String resp =  HttpUtils.sendGet(url,null);
+            logger.info("actuator:" + resp);
+            if (StringUtils.isEmpty(resp)) {
+                isHealth = false;
+            }
+            JSONObject jsonObject = JSON.parseObject(resp);
+            if (!"UP".equals(jsonObject.getString("status"))) {
+                isHealth = false;
+            }
+            logger.info("IailabModelService is UP");
+        } catch (Exception e) {
+            isHealth = false;
+            e.printStackTrace();
+        }
+        if (!isHealth) {
+            logger.info("IailabModelService is DOWN");
+            restartIailabModelServiceTask.run("");
+        }
+        logger.info("CheckIailabModelServiceTask运行完成");
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3