diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ScheduleGroup.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ScheduleGroup.java index abd3656e48..378c0a588b 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ScheduleGroup.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ScheduleGroup.java @@ -1,6 +1,6 @@ package io.metersphere.commons.constants; public enum ScheduleGroup { - API_TEST, PERFORMANCE_TEST, API_SCENARIO_TEST, TEST_PLAN_TEST, SWAGGER_IMPORT, ISSUE_SYNC, + PERFORMANCE_TEST, API_SCENARIO_TEST, TEST_PLAN_TEST, SWAGGER_IMPORT, ISSUE_SYNC, SCHEDULE_SEND_REPORT, CLEAN_UP_REPORT, UI_SCENARIO_TEST } 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 897c4cae53..512fae7ae1 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 @@ -129,13 +129,13 @@ public class BaseScheduleService { return scheduleMapper.deleteByExample(scheduleExample); } - private void removeJob(String resourceId, String group) { - scheduleManager.removeJob(new JobKey(resourceId, ScheduleGroup.PERFORMANCE_TEST.name()), new TriggerKey(resourceId, group)); + private void removeJob(String key, String group) { + scheduleManager.removeJob(new JobKey(key, group), new TriggerKey(key, group)); } - public List getEnableSchedule(ScheduleGroup group) { + public List getScheduleByGroup(ScheduleGroup group) { ScheduleExample example = new ScheduleExample(); - example.createCriteria().andEnableEqualTo(true) + example.createCriteria() .andGroupEqualTo(group.name()); return scheduleMapper.selectByExample(example); } @@ -149,17 +149,19 @@ public class BaseScheduleService { } public void startEnableSchedules(ScheduleGroup group) { - List Schedules = getEnableSchedule(group); - + List Schedules = getScheduleByGroup(group); Schedules.forEach(schedule -> { try { + // 兼容历史数据 + jobConvert(schedule, group); 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(), scheduleManager.getDefaultJobDataMap(schedule, schedule.getValue(), schedule.getUserId())); + } else { + // 删除关闭的job + removeJob(schedule.getKey(), group.toString()); } } catch (Exception e) { LogUtil.error("初始化任务失败", e); diff --git a/project-management/backend/src/main/java/io/metersphere/listener/ProjectAppStartListener.java b/project-management/backend/src/main/java/io/metersphere/listener/ProjectAppStartListener.java index ce5b335750..920f944809 100644 --- a/project-management/backend/src/main/java/io/metersphere/listener/ProjectAppStartListener.java +++ b/project-management/backend/src/main/java/io/metersphere/listener/ProjectAppStartListener.java @@ -1,6 +1,9 @@ package io.metersphere.listener; +import io.metersphere.commons.constants.ScheduleGroup; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.service.BaseScheduleService; +import jakarta.annotation.Resource; import org.apache.jmeter.util.JMeterUtils; import org.python.core.Options; import org.python.util.PythonInterpreter; @@ -13,6 +16,10 @@ import java.util.Objects; @Component public class ProjectAppStartListener implements ApplicationListener { + + @Resource + private BaseScheduleService baseScheduleService; + @Override public void onApplicationEvent(ApplicationReadyEvent event) { LogUtil.info("================= PROJECT 应用启动 ================="); @@ -21,6 +28,8 @@ public class ProjectAppStartListener implements ApplicationListener