性能测试接口删除时移除定时任务

This commit is contained in:
2025-04-18 11:30:43 +08:00
parent cacba80269
commit defa663b4c
2 changed files with 24 additions and 1 deletions

View File

@@ -212,11 +212,12 @@ public class PerformanceTestController extends BaseController {
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
@PutMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
dynamicTaskManager.removeTasks(ids);
return toAjax(performanceTestService.deletePerformanceTestByIds(ids));
}
/**
* 删除性能测试
* 立即执行性能测试
*/
// @PreAuthorize("@ss.hasPermi('system:test:remove')")
@GetMapping("/executeNow")

View File

@@ -75,6 +75,28 @@ public class DynamicTaskManager {
}
}
/**
* 移除定时任务
* @param taskId 任务ID
*/
public void removeTask(Long taskId) {
if (scheduledTasks.containsKey(taskId)) {
scheduledTasks.get(taskId).cancel(true);
scheduledTasks.remove(taskId);
taskCache.remove(taskId);
log.info("已移除定时任务: {}", taskId);
}
}
/**
* 批量移除定时任务
* @param taskIds 任务ID数组
*/
public void removeTasks(Long[] taskIds) {
for (Long taskId : taskIds) {
removeTask(taskId);
}
}
private void loadTasks() {
PerformanceTest performanceTest =new PerformanceTest();
performanceTest.setCrontabStatus(1);