diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseScheduleService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseScheduleService.java index 110b8cf333..d4bb3f2b79 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseScheduleService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseScheduleService.java @@ -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 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(),