扫表检测渲染任务问题

This commit is contained in:
Jerry Yan 2025-02-21 10:24:30 +08:00
parent f0fc5ef236
commit b51b3260c7

View File

@ -0,0 +1,47 @@
package com.ycwl.basic.watchdog;
import com.ycwl.basic.mapper.TaskMapper;
import com.ycwl.basic.model.pc.task.entity.TaskEntity;
import com.ycwl.basic.notify.NotifyFactory;
import com.ycwl.basic.notify.entity.NotifyContent;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Profile("prod")
public class TaskWatchDog {
@Autowired
private TaskMapper taskMapper;
@Scheduled(fixedDelay = 1000 * 60L)
public void scanTaskStatus() {
List<TaskEntity> allNotRunningTaskList = taskMapper.selectAllNotRunning();
String title = "任务堆积警告!";
StringBuilder content = new StringBuilder();
if (allNotRunningTaskList.size() > 10) {
content.append("当前任务队列中存在超过10个未运行任务请及时处理");
}
List<TaskEntity> allRunningTaskList = taskMapper.selectAllRunning();
for (TaskEntity taskEntity : allRunningTaskList) {
if (taskEntity.getStartTime() == null) {
continue;
}
// startTime已经过去3分钟了
if (System.currentTimeMillis() - taskEntity.getStartTime().getTime() > 1000 * 60 * 3) {
content.append("当前【").append(taskEntity.getWorkerId()).append("】渲染机的【").append(taskEntity.getId()).append("】任务已超过3分钟未完成");
}
}
if (StringUtils.isNotBlank(content)) {
NotifyFactory.via().sendTo(
new NotifyContent(title, content.toString()),
"default_user"
);
}
}
}