From be1c4e1ffb446eeb333579b7d092e5d42c6119ef Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 7 Feb 2023 14:40:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=BE=AE=E6=9C=8D=E5=8A=A1=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1022487 --user=赵勇 【定时任务】2.2.1版本升级到2.6.1版本,测试计划和接口场景的定时任务初始化报错,也没按时执行 https://www.tapd.cn/55049933/s/1332341 --- .../io/metersphere/service/BaseScheduleService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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(),