diff --git a/backend/src/main/java/io/metersphere/service/ScheduleService.java b/backend/src/main/java/io/metersphere/service/ScheduleService.java index ede5772f98..13c41490ba 100644 --- a/backend/src/main/java/io/metersphere/service/ScheduleService.java +++ b/backend/src/main/java/io/metersphere/service/ScheduleService.java @@ -7,6 +7,7 @@ import io.metersphere.base.mapper.ScheduleMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.job.sechedule.ApiTestJob; import io.metersphere.job.sechedule.ScheduleManager; import org.apache.commons.lang3.StringUtils; import org.quartz.JobKey; @@ -52,12 +53,15 @@ public class ScheduleService { } public int deleteSchedule(String scheduleId) { + Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId); + removeJob(schedule.getResourceId()); return scheduleMapper.deleteByPrimaryKey(scheduleId); } public int deleteByResourceId(String resourceId) { ScheduleExample scheduleExample = new ScheduleExample(); scheduleExample.createCriteria().andResourceIdEqualTo(resourceId); + removeJob(resourceId); return scheduleMapper.deleteByExample(scheduleExample); } @@ -99,6 +103,10 @@ public class ScheduleService { return schedule; } + public void removeJob(String resourceId) { + scheduleManager.removeJob(ApiTestJob.getJobKey(resourceId), ApiTestJob.getTriggerKey(resourceId)); + } + public void addOrUpdateCronJob(Schedule request, JobKey jobKey, TriggerKey triggerKey, Class clazz) { Boolean enable = request.getEnable(); String cronExpression = request.getValue();