From e12bf8e7ebf5110dc55dd48cced60c23b36ea380 Mon Sep 17 00:00:00 2001 From: 18idc <993143799@qq.com> Date: Fri, 9 Apr 2021 21:49:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClearInvalidLoginUserCacheTimer.java | 2 +- .../roses/kernel/timer/api/TimerAction.java | 3 +- .../kernel/timer/api/TimerExeService.java | 3 +- .../timer/modular/entity/SysTimers.java | 6 ++++ .../modular/listener/TaskRunListener.java | 2 +- .../timer/modular/param/SysTimersParam.java | 5 +++ .../service/impl/SysTimersServiceImpl.java | 31 +++++++++++++------ .../modular/tasks/SystemOutTaskRunner.java | 5 +-- .../hutool/HutoolTimerExeServiceImpl.java | 4 +-- .../holder/SystemHardwareInfoHolder.java | 2 +- 10 files changed, 45 insertions(+), 18 deletions(-) diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/timer/ClearInvalidLoginUserCacheTimer.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/timer/ClearInvalidLoginUserCacheTimer.java index 2eca0ec49..53ead90f6 100644 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/timer/ClearInvalidLoginUserCacheTimer.java +++ b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/timer/ClearInvalidLoginUserCacheTimer.java @@ -33,7 +33,7 @@ public class ClearInvalidLoginUserCacheTimer implements TimerAction { } @Override - public void action() { + public void action(String params) { Collection allOnlineUsers = allPlaceLoginTokenCache.getAllKeys(); if (ObjectUtil.isNotEmpty(allOnlineUsers)) { for (String userId : allOnlineUsers) { diff --git a/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerAction.java b/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerAction.java index 4a87c000e..c5505dcfc 100644 --- a/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerAction.java +++ b/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerAction.java @@ -37,9 +37,10 @@ public interface TimerAction { /** * 任务执行的具体内容 * + * @param params 任务参数 * @author stylefeng * @date 2020/6/28 21:29 */ - void action(); + void action(String params); } diff --git a/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerExeService.java b/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerExeService.java index b6a5a5175..73d27b8c2 100644 --- a/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerExeService.java +++ b/kernel-d-timer/timer-api/src/main/java/cn/stylefeng/roses/kernel/timer/api/TimerExeService.java @@ -58,10 +58,11 @@ public interface TimerExeService { * @param taskId 任务id * @param cron cron表达式 * @param className 类的全名,必须是TimerAction的子类 + * @param params 自定义参数 * @author stylefeng * @date 2020/7/1 13:51 */ - void startTimer(String taskId, String cron, String className); + void startTimer(String taskId, String cron, String className, String params); /** * 停止一个定时器 diff --git a/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/entity/SysTimers.java b/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/entity/SysTimers.java index 7b784346c..c17422f1d 100644 --- a/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/entity/SysTimers.java +++ b/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/entity/SysTimers.java @@ -64,6 +64,12 @@ public class SysTimers extends BaseEntity { @TableField("cron") private String cron; + /** + * 参数 + */ + @TableField("params") + private String params; + /** * 状态:1-运行,2-停止 */ diff --git a/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/listener/TaskRunListener.java b/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/listener/TaskRunListener.java index f1b2834df..154b67e87 100644 --- a/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/listener/TaskRunListener.java +++ b/kernel-d-timer/timer-business/src/main/java/cn/stylefeng/roses/kernel/timer/modular/listener/TaskRunListener.java @@ -63,7 +63,7 @@ public class TaskRunListener implements ApplicationListener wrapper = new LambdaUpdateWrapper<>(); - wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.RUNNING.getCode()) - .eq(SysTimers::getTimerId, sysTimersParam.getTimerId()); + wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.RUNNING.getCode()).eq(SysTimers::getTimerId, sysTimersParam.getTimerId()); this.update(wrapper); // 添加定时任务调度 SysTimers sysTimers = this.querySysTimers(sysTimersParam); - timerExeService.startTimer(String.valueOf(sysTimers.getTimerId()), sysTimers.getCron(), sysTimers.getActionClass()); + timerExeService.startTimer(String.valueOf(sysTimers.getTimerId()), sysTimers.getCron(), sysTimers.getActionClass(), sysTimers.getParams()); } @Transactional(rollbackFor = Exception.class) @@ -137,8 +138,7 @@ public class SysTimersServiceImpl extends ServiceImpl wrapper = new LambdaUpdateWrapper<>(); - wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.STOP.getCode()) - .eq(SysTimers::getTimerId, sysTimersParam.getTimerId()); + wrapper.set(SysTimers::getJobStatus, TimerJobStatusEnum.STOP.getCode()).eq(SysTimers::getTimerId, sysTimersParam.getTimerId()); this.update(wrapper); // 关闭定时任务调度 @@ -231,4 +231,17 @@ public class SysTimersServiceImpl extends ServiceImpl { try { TimerAction timerAction = (TimerAction) SpringUtil.getBean(Class.forName(className)); - timerAction.action(); + timerAction.action(params); } catch (ClassNotFoundException e) { log.error("任务执行异常:{}", e.getMessage()); } diff --git a/kernel-o-monitor/monitor-sdk-system-info/src/main/java/cn/stylefeng/roses/kernel/monitor/system/holder/SystemHardwareInfoHolder.java b/kernel-o-monitor/monitor-sdk-system-info/src/main/java/cn/stylefeng/roses/kernel/monitor/system/holder/SystemHardwareInfoHolder.java index ca8c4c064..f842b315f 100644 --- a/kernel-o-monitor/monitor-sdk-system-info/src/main/java/cn/stylefeng/roses/kernel/monitor/system/holder/SystemHardwareInfoHolder.java +++ b/kernel-o-monitor/monitor-sdk-system-info/src/main/java/cn/stylefeng/roses/kernel/monitor/system/holder/SystemHardwareInfoHolder.java @@ -38,7 +38,7 @@ public class SystemHardwareInfoHolder implements TimerAction { private SystemHardwareCalculator systemHardwareCalculator = null; @Override - public void action() { + public void action(String params) { SystemHardwareCalculator newInfo = new SystemHardwareCalculator(); newInfo.calc(); systemHardwareCalculator = newInfo;