fix(接口测试): 兼容微服务之前版本的定时任务初始化
--bug=1022487 --user=赵勇 【定时任务】2.2.1版本升级到2.6.1版本,测试计划和接口场景的定时任务初始化报错,也没按时执行 https://www.tapd.cn/55049933/s/1332341
This commit is contained in:
parent
a6ce6765e9
commit
be1c4e1ffb
|
@ -30,6 +30,7 @@ import org.quartz.TriggerKey;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -45,6 +46,9 @@ public class BaseScheduleService {
|
|||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
private final String API_SCENARIO_JOB = "io.metersphere.sechedule.ApiScenarioTestJob";
|
||||
private final String API_SWAGGER_IMPORT_JOB = "io.metersphere.sechedule.SwaggerUrlImportJob";
|
||||
|
||||
public void addSchedule(Schedule schedule) {
|
||||
schedule.setId(UUID.randomUUID().toString());
|
||||
schedule.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -135,12 +139,21 @@ public class BaseScheduleService {
|
|||
return scheduleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
private void jobConvert(Schedule schedule, ScheduleGroup group) {
|
||||
switch (group) {
|
||||
case API_SCENARIO_TEST -> schedule.setJob(API_SCENARIO_JOB);
|
||||
case SWAGGER_IMPORT -> schedule.setJob(API_SWAGGER_IMPORT_JOB);
|
||||
}
|
||||
}
|
||||
|
||||
public void startEnableSchedules(ScheduleGroup group) {
|
||||
List<Schedule> Schedules = getEnableSchedule(group);
|
||||
|
||||
Schedules.forEach(schedule -> {
|
||||
try {
|
||||
if (schedule.getEnable()) {
|
||||
// 兼容历史数据
|
||||
jobConvert(schedule, group);
|
||||
LogUtil.info("初始化任务:" + JSON.toJSONString(schedule));
|
||||
scheduleManager.addOrUpdateCronJob(new JobKey(schedule.getKey(), schedule.getGroup()),
|
||||
new TriggerKey(schedule.getKey(), schedule.getGroup()), Class.forName(schedule.getJob()), schedule.getValue(),
|
||||
|
|
Loading…
Reference in New Issue