From defa663b4cadc09199fa776bcf11919a7898c087 Mon Sep 17 00:00:00 2001 From: FBODC Date: Fri, 18 Apr 2025 11:30:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=88=A0=E9=99=A4=E6=97=B6=E7=A7=BB=E9=99=A4=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PerformanceTestController.java | 3 ++- .../test/test/task/DynamicTaskManager.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java b/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java index 102eda1..32fc480 100644 --- a/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java +++ b/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java @@ -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") diff --git a/test-test/src/main/java/com/test/test/task/DynamicTaskManager.java b/test-test/src/main/java/com/test/test/task/DynamicTaskManager.java index 8eff020..632ee0c 100644 --- a/test-test/src/main/java/com/test/test/task/DynamicTaskManager.java +++ b/test-test/src/main/java/com/test/test/task/DynamicTaskManager.java @@ -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);