TaskInitRunner.java
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.viontech.fanxing.task.runner;
import com.viontech.fanxing.commons.constant.TaskStatus;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample;
import com.viontech.fanxing.task.mapper.TaskMapper;
import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.service.TaskDataService;
import com.viontech.fanxing.task.utils.TaskUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/9/2
*/
@Component
@Slf4j
@Profile("!test")
public class TaskInitRunner implements CommandLineRunner {
@Resource
private TaskMapper taskMapper;
@Resource
private TaskDataService taskDataService;
@Override
public void run(String... args) throws Exception {
log.info("===================任务初始化开始===================");
List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
for (Task task : tasks) {
// scene和storage不为空,不处于未部署状态
if (TaskUtils.INSTANCE.canRun(task)) {
try {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) {
taskDataService.addTask(task);
} else if (taskData.getTask().getStatus() == TaskStatus.RUNNING.val) {
taskDataService.distributeTask(taskData);
}
} catch (Exception e) {
log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage());
}
}
}
log.info("===================任务初始化结束===================");
}
}