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运行完成"); } }