14
14
import com .dtstack .taier .scheduler .service .ScheduleJobService ;
15
15
import com .google .common .collect .Lists ;
16
16
import org .apache .commons .collections .CollectionUtils ;
17
- import org .slf4j .Logger ;
18
- import org .slf4j .LoggerFactory ;
19
17
import org .springframework .beans .factory .annotation .Autowired ;
20
18
21
19
import java .util .ArrayList ;
20
+ import java .util .Comparator ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
24
23
import java .util .Set ;
@@ -44,39 +43,46 @@ public abstract class OperatorRecordJobScheduler extends AbstractJobSummitSchedu
44
43
@ Autowired
45
44
private ScheduleJobOperatorRecordService scheduleJobOperatorRecordService ;
46
45
46
+ private Long operatorRecordStartId = 0L ;
47
+
47
48
@ Override
48
49
protected List <ScheduleJobDetails > listExecJob (Long startSort , String nodeAddress , Boolean isEq ) {
49
- List <ScheduleJobOperatorRecord > records = scheduleJobOperatorRecordService .listOperatorRecord (startSort , nodeAddress , getOperatorType ().getType (), isEq );
50
-
51
- if (CollectionUtils .isNotEmpty (records )) {
52
- Set <String > jobIds = records .stream ().map (ScheduleJobOperatorRecord ::getJobId ).collect (Collectors .toSet ());
53
- List <ScheduleJob > scheduleJobList = getScheduleJob (jobIds );
54
-
55
- if (CollectionUtils .isNotEmpty (scheduleJobList )) {
56
- List <String > jodExecIds = scheduleJobList .stream ().map (ScheduleJob ::getJobId ).collect (Collectors .toList ());
57
- if (jobIds .size () != scheduleJobList .size ()) {
58
- // 过滤出来已经提交运行的实例,删除操作记录
59
- List <String > deleteJobIdList = jobIds .stream ().filter (jobId -> !jodExecIds .contains (jobId )).collect (Collectors .toList ());
60
- removeOperatorRecord (deleteJobIdList );
61
- }
50
+ List <ScheduleJobOperatorRecord > records = scheduleJobOperatorRecordService .listOperatorRecord (operatorRecordStartId , nodeAddress , getOperatorType ().getType (), isEq );
51
+ //empty
52
+ if (CollectionUtils .isEmpty (records )) {
53
+ operatorRecordStartId = 0L ;
54
+ return new ArrayList <>();
55
+ }
62
56
63
- List <String > jobKeys = scheduleJobList .stream ().map (ScheduleJob ::getJobKey ).collect (Collectors .toList ());
64
- List <ScheduleJobJob > scheduleJobJobList = scheduleJobJobService .listByJobKeys (jobKeys );
65
- Map <String , List <ScheduleJobJob >> jobJobMap = scheduleJobJobList .stream ().collect (Collectors .groupingBy (ScheduleJobJob ::getJobKey ));
66
- List <ScheduleJobDetails > scheduleJobDetailsList = new ArrayList <>(scheduleJobList .size ());
57
+ Set <String > jobIds = records .stream ().map (ScheduleJobOperatorRecord ::getJobId ).collect (Collectors .toSet ());
58
+ List <ScheduleJob > scheduleJobList = getScheduleJob (jobIds );
67
59
68
- for (ScheduleJob scheduleJob : scheduleJobList ) {
69
- ScheduleJobDetails scheduleJobDetails = new ScheduleJobDetails ();
70
- scheduleJobDetails .setScheduleJob (scheduleJob );
71
- scheduleJobDetails .setJobJobList (jobJobMap .get (scheduleJob .getJobKey ()));
72
- scheduleJobDetailsList .add (scheduleJobDetails );
73
- }
74
- return scheduleJobDetailsList ;
75
- } else {
76
- removeOperatorRecord (Lists .newArrayList (jobIds ));
77
- }
60
+ if (CollectionUtils .isEmpty (scheduleJobList )) {
61
+ operatorRecordStartId = 0L ;
62
+ removeOperatorRecord (Lists .newArrayList (jobIds ));
78
63
}
79
- return Lists .newArrayList ();
64
+
65
+ //set max
66
+ records .stream ().max (Comparator .comparing (ScheduleJobOperatorRecord ::getId ))
67
+ .ifPresent (scheduleJobOperatorRecord -> operatorRecordStartId = scheduleJobOperatorRecord .getId ());
68
+
69
+ if (jobIds .size () != scheduleJobList .size ()) {
70
+ List <String > jodExecIds = scheduleJobList .stream ().map (ScheduleJob ::getJobId ).collect (Collectors .toList ());
71
+ // 过滤出来已经提交运行的实例,删除操作记录
72
+ List <String > deleteJobIdList = jobIds .stream ().filter (jobId -> !jodExecIds .contains (jobId )).collect (Collectors .toList ());
73
+ removeOperatorRecord (deleteJobIdList );
74
+ }
75
+
76
+ List <String > jobKeys = scheduleJobList .stream ().map (ScheduleJob ::getJobKey ).collect (Collectors .toList ());
77
+ List <ScheduleJobJob > scheduleJobJobList = scheduleJobJobService .listByJobKeys (jobKeys );
78
+ Map <String , List <ScheduleJobJob >> jobJobMap = scheduleJobJobList .stream ().collect (Collectors .groupingBy (ScheduleJobJob ::getJobKey ));
79
+
80
+ return scheduleJobList .stream ().map (scheduleJob -> {
81
+ ScheduleJobDetails scheduleJobDetails = new ScheduleJobDetails ();
82
+ scheduleJobDetails .setScheduleJob (scheduleJob );
83
+ scheduleJobDetails .setJobJobList (jobJobMap .get (scheduleJob .getJobKey ()));
84
+ return scheduleJobDetails ;
85
+ }).collect (Collectors .toList ());
80
86
}
81
87
82
88
/**
0 commit comments