fix: 新增手动启动定时任务接口

This commit is contained in:
zhangyanduan
2022-10-21 09:47:06 +08:00
parent 04749fd69d
commit 9542200d13
2 changed files with 41 additions and 1 deletions
@@ -9,6 +9,7 @@ package com.adc.da.search.conf;
import com.adc.da.slrs.tsTask.dao.TbTaskDao;
import com.adc.da.slrs.tsTask.entity.TbTask;
import com.adc.da.slrs.tsTask.service.ITbTaskService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -95,7 +96,7 @@ public class SchedulerConf {
log.info("{},任务启动!", taskId);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
log.error("{},任务启动失败...", taskId);
e.printStackTrace();
log.error(e.getMessage(),e);
}
}
@@ -113,6 +114,28 @@ public class SchedulerConf {
log.info("{},任务停止...", taskId);
}
public TbTask manualRunTask(String taskId){
TbTask task = iTbTaskService.getById(taskId);
if(task!=null){
try {
//获取并实例化Runnable任务类
Class<?> clazz = Class.forName(task.getTaskClass());
Runnable runnable = (Runnable) clazz.newInstance();
Thread runTaskThread = new Thread(runnable);
runTaskThread.start();
log.info("{},任务开始启动执行!", task.getTaskName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
log.error("{},任务启动失败...", task.getTaskName());
log.error(e.getMessage(),e);
}
return task;
}else{
return null;
}
}
/**
* 根据ip开启定时任务
*/