update:自启动定时任务增加参数主机管控

This commit is contained in:
zyd
2022-10-01 19:08:12 +08:00
parent d4e592e21f
commit 8a77f17b43
@@ -11,6 +11,7 @@ import com.adc.da.slrs.tsTask.entity.TbTask;
import com.adc.da.slrs.tsTask.service.ITbTaskService; import com.adc.da.slrs.tsTask.service.ITbTaskService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger; import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -44,6 +45,10 @@ public class SchedulerConf {
@Autowired @Autowired
ITbTaskService iTbTaskService; ITbTaskService iTbTaskService;
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
/** /**
* 初始化线程池任务调度 * 初始化线程池任务调度
*/ */
@@ -112,25 +117,23 @@ public class SchedulerConf {
* 根据ip开启定时任务 * 根据ip开启定时任务
*/ */
public void startByIp() throws Exception { public void startByIp() throws Exception {
// InetAddress addr = InetAddress.getLocalHost(); if(isNotScheduled){
// log.info("Local HostAddress: "+addr.getHostAddress()); List<String> addr = getIpAddress();
// String hostname = addr.getHostName(); //查询
// log.info("Local host name: "+hostname); List<TbTask> tbTaskList = tbTaskDao.selectList(null);
List<String> addr = getIpAddress(); for (TbTask tbTask : tbTaskList) {
//查询 if (addr == null){
List<TbTask> tbTaskList = tbTaskDao.selectList(null); log.error("本机地址未获取到!!");
for (TbTask tbTask : tbTaskList) { break;
if (addr == null){ }
log.error("本机地址未获取到!!"); String ips = tbTask.getIp();
break; String[] ipArray = ips.split(",");
} for (String realIp : ipArray) {
String ips = tbTask.getIp(); if (addr.contains(realIp)) {
String[] ipArray = ips.split(","); log.info("本机ip地址:" + addr);
for (String realIp : ipArray) { this.start(tbTask.getId());
if (addr.contains(realIp)) { log.info("执行了:" + tbTask.getTaskDesc());
log.info("本机ip地址:" + addr); }
this.start(tbTask.getId());
log.info("执行了:" + tbTask.getTaskDesc());
} }
} }
} }