代码调整

This commit is contained in:
2023-12-06 09:31:06 +08:00
parent 09bfde0103
commit 0101a85a38
4 changed files with 31 additions and 1 deletions

View File

@@ -164,5 +164,19 @@ public class TimersController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 执行一次定时任务
*
* @author hongawen
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/run")
@ApiOperation("执行一次定时任务")
public HttpResult<Object> run(String id) {
String methodDescribe = getMethodDescribe("run");
timersService.run(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -31,4 +31,6 @@ public interface ITimersService extends IService<Timers> {
void start(String id);
void stop(String id);
void run(String id);
}

View File

@@ -104,7 +104,7 @@ public class TimersServiceImpl extends ServiceImpl<TimersMapper, Timers> impleme
// 更新库中的状态
LambdaUpdateWrapper<Timers> wrapper = new LambdaUpdateWrapper<>();
wrapper.set(Timers::getJobStatus, TimerJobStatusEnum.RUNNING.getCode())
.eq(Timers::getId,id);
.eq(Timers::getId, id);
this.update(wrapper);
// 添加定时任务调度
@@ -125,6 +125,19 @@ public class TimersServiceImpl extends ServiceImpl<TimersMapper, Timers> impleme
timerExeService.stopTimer(sysTimers.getId());
}
@Override
public void run(String id) {
Timers sysTimers = this.queryTimers(id);
String actionClass = sysTimers.getActionClass();
TimerTaskRunner timerTaskRunner;
try {
timerTaskRunner = (TimerTaskRunner) SpringUtil.getBean(Class.forName(actionClass));
} catch (ClassNotFoundException e) {
throw new BusinessException(SystemResponseEnum.TIMER_NO_CLASS);
}
timerTaskRunner.action();
}
/**
* 获取定时任务
*