refactor(系統): 初始化定时任务分页处理
This commit is contained in:
parent
693a2f9fef
commit
fd5ad458be
|
@ -2,6 +2,7 @@ package io.metersphere.system.mapper;
|
|||
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.dto.taskcenter.TaskCenterScheduleDTO;
|
||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterSchedulePageRequest;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -29,4 +30,6 @@ public interface ExtScheduleMapper {
|
|||
long countQuartzTriggersByResourceId(String scheduleId);
|
||||
|
||||
long countQuartzCronTriggersByResourceId(String scheduleId);
|
||||
|
||||
List<Schedule> getScheduleByLimit(@Param("start") int start, @Param("limit") int limit);
|
||||
}
|
||||
|
|
|
@ -118,5 +118,8 @@
|
|||
WHERE resource_id = #{0}
|
||||
</select>
|
||||
|
||||
<select id="getScheduleByLimit" resultType="io.metersphere.system.domain.Schedule">
|
||||
SELECT * FROM schedule ORDER BY create_time LIMIT #{start}, #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -4,6 +4,7 @@ import io.metersphere.sdk.util.JSON;
|
|||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
import io.metersphere.system.domain.ScheduleExample;
|
||||
import io.metersphere.system.mapper.ExtScheduleMapper;
|
||||
import io.metersphere.system.mapper.ScheduleMapper;
|
||||
import io.metersphere.system.schedule.ScheduleManager;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -22,15 +23,28 @@ public class BaseScheduleService {
|
|||
private ScheduleMapper scheduleMapper;
|
||||
@Resource
|
||||
private ScheduleManager scheduleManager;
|
||||
@Resource
|
||||
private ExtScheduleMapper extScheduleMapper;
|
||||
|
||||
public void startEnableSchedules() {
|
||||
List<Schedule> Schedules = getSchedule();
|
||||
Schedules.forEach(schedule -> {
|
||||
ScheduleExample example = new ScheduleExample();
|
||||
example.createCriteria();
|
||||
long count = scheduleMapper.countByExample(example);
|
||||
long pages = Double.valueOf(Math.ceil(count / 100.0)).longValue();
|
||||
for (int i = 0; i < pages; i++) {
|
||||
int start = i * 100;
|
||||
List<Schedule> schedules = extScheduleMapper.getScheduleByLimit(start, 100);
|
||||
doHandleSchedule(schedules);
|
||||
}
|
||||
}
|
||||
|
||||
private void doHandleSchedule(List<Schedule> schedules) {
|
||||
schedules.forEach(schedule -> {
|
||||
try {
|
||||
if (schedule.getEnable()) {
|
||||
LogUtils.info("初始化任务:" + JSON.toJSONString(schedule));
|
||||
scheduleManager.addOrUpdateCronJob(new JobKey(schedule.getKey(), schedule.getJob()),
|
||||
new TriggerKey(schedule.getKey(),schedule.getJob()), Class.forName(schedule.getJob()), schedule.getValue(),
|
||||
new TriggerKey(schedule.getKey(), schedule.getJob()), Class.forName(schedule.getJob()), schedule.getValue(),
|
||||
scheduleManager.getDefaultJobDataMap(schedule, schedule.getValue(), schedule.getCreateUser()));
|
||||
} else {
|
||||
// 删除关闭的job
|
||||
|
@ -40,13 +54,6 @@ public class BaseScheduleService {
|
|||
LogUtils.error("初始化任务失败", e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private List<Schedule> getSchedule() {
|
||||
ScheduleExample example = new ScheduleExample();
|
||||
example.createCriteria();
|
||||
return scheduleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
private void removeJob(Schedule schedule) {
|
||||
|
|
Loading…
Reference in New Issue