|
@@ -1,6 +1,7 @@
|
|
package com.css.simulation.resource.scheduler.scheduler;
|
|
package com.css.simulation.resource.scheduler.scheduler;
|
|
|
|
|
|
import api.common.pojo.constants.DictConstants;
|
|
import api.common.pojo.constants.DictConstants;
|
|
|
|
+import api.common.util.CollectionUtil;
|
|
import api.common.util.LinuxUtil;
|
|
import api.common.util.LinuxUtil;
|
|
import api.common.util.StringUtil;
|
|
import api.common.util.StringUtil;
|
|
import api.common.util.TimeUtil;
|
|
import api.common.util.TimeUtil;
|
|
@@ -42,31 +43,26 @@ public class TickScheduler {
|
|
public void tick() {
|
|
public void tick() {
|
|
|
|
|
|
ArrayList<TaskPO> executingTaskList = taskMapper.selectExecuting();
|
|
ArrayList<TaskPO> executingTaskList = taskMapper.selectExecuting();
|
|
- if (executingTaskList != null && executingTaskList.size() > 0) {
|
|
|
|
|
|
+ if (CollectionUtil.isEmpty(executingTaskList)) {
|
|
// log.info("------- TickScheduler 查询出所有执行中的任务('Running'):" + executingTaskList);
|
|
// log.info("------- TickScheduler 查询出所有执行中的任务('Running'):" + executingTaskList);
|
|
//2 根据 key 查出任务的心跳时间
|
|
//2 根据 key 查出任务的心跳时间
|
|
-
|
|
|
|
for (TaskPO task : executingTaskList) {
|
|
for (TaskPO task : executingTaskList) {
|
|
String taskId = task.getId();
|
|
String taskId = task.getId();
|
|
String projectId = task.getPId();
|
|
String projectId = task.getPId();
|
|
- try {
|
|
|
|
- String s = redisTemplate.opsForValue().get(manualProjectTopic + ":" + projectId + ":" + taskId);
|
|
|
|
|
|
+ String s = redisTemplate.opsForValue().get(manualProjectTopic + ":" + projectId + ":" + taskId);
|
|
// Optional.ofNullable(s).orElseThrow(() -> new RuntimeException("项目 " + projectId + " 下的任务 " + taskId + " 的心跳查询失败"));
|
|
// Optional.ofNullable(s).orElseThrow(() -> new RuntimeException("项目 " + projectId + " 下的任务 " + taskId + " 的心跳查询失败"));
|
|
- assert s != null;
|
|
|
|
- long tickTime = Long.parseLong(s);
|
|
|
|
- long timeout = 2 * 60 * 1000L;
|
|
|
|
- long now = TimeUtil.getNow();
|
|
|
|
- long difference = now - tickTime;
|
|
|
|
|
|
+ assert s != null;
|
|
|
|
+ long tickTime = Long.parseLong(s);
|
|
|
|
+ long timeout = 2 * 60 * 1000L;
|
|
|
|
+ long now = TimeUtil.getNow();
|
|
|
|
+ long difference = now - tickTime;
|
|
// log.info("------- TickScheduler 任务" + taskId + "心跳时间为:" + tickTime + "最大仿真时间为:" + tickTime + "时间差为:" + difference);
|
|
// log.info("------- TickScheduler 任务" + taskId + "心跳时间为:" + tickTime + "最大仿真时间为:" + tickTime + "时间差为:" + difference);
|
|
- if (difference > timeout) {
|
|
|
|
- log.info("------- TickScheduler 任务" + taskId + "已超时,状态修改为:" + DictConstants.TASK_ABORTED);
|
|
|
|
- String podName = redisTemplate.opsForValue().get("podName:" + taskId);
|
|
|
|
- if (podName != null) {
|
|
|
|
- taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
|
|
|
|
- }
|
|
|
|
|
|
+ if (difference > timeout) {
|
|
|
|
+ log.info("------- TickScheduler 任务" + taskId + "已超时,状态修改为:" + DictConstants.TASK_ABORTED);
|
|
|
|
+ String podName = redisTemplate.opsForValue().get("podName:" + taskId);
|
|
|
|
+ if (podName != null) {
|
|
|
|
+ taskService.taskState(taskId, DictConstants.TASK_ABORTED, podName);
|
|
}
|
|
}
|
|
- } catch (Exception e) {
|
|
|
|
- throw new RuntimeException(e.getMessage());
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|