1.增加国网上送定时任务,重试机制

2.拆分国网上送定时任务接口
This commit is contained in:
wr
2024-01-08 16:40:08 +08:00
parent bd89190ddc
commit 51c5843cb7
9 changed files with 149 additions and 22 deletions

View File

@@ -6,11 +6,11 @@ import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.log.Log;
import cn.hutool.setting.Setting;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.system.enums.SystemResponseEnum;
import com.njcn.system.timer.TimerExeService;
import com.njcn.system.timer.TimerTaskRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
@@ -22,7 +22,10 @@ import org.springframework.stereotype.Service;
public class HutoolTimerExeServiceImpl implements TimerExeService {
private static final Log log = Log.get();
@Value("${runTake.maxRetryCount}")
private Integer maxRetryCount;
@Value("${runTake.delayTime}")
private Integer delayTime;
@Override
public void startTimer(String taskId, String cron, String className) {
@@ -41,9 +44,11 @@ public class HutoolTimerExeServiceImpl implements TimerExeService {
Task task = () -> {
try {
TimerTaskRunner timerTaskRunner = (TimerTaskRunner) SpringUtil.getBean(Class.forName(className));
timerTaskRunner.action();
runTaskWithRetryAndDelay(timerTaskRunner);
} catch (ClassNotFoundException e) {
log.error(">>> 任务执行异常:{}", e.getMessage());
} catch (InterruptedException e) {
log.error(">>> 运行任务执行异常:{}", e.getMessage());
}
};
@@ -56,4 +61,22 @@ public class HutoolTimerExeServiceImpl implements TimerExeService {
CronUtil.remove(taskId);
}
public void runTaskWithRetryAndDelay(TimerTaskRunner timerTaskRunner) throws InterruptedException {
int retryCount = 0; // 重试次数计数器
while (retryCount < maxRetryCount) {
try {
System.out.println("重试机制:"+(retryCount+1));
timerTaskRunner.action();
return; // 任务执行成功,跳出循环
} catch (Exception e) {
// 处理异常
retryCount++; // 增加重试次数
Thread.sleep(delayTime); // 等待一段时间
}
}
if (retryCount >= maxRetryCount) {
// 达到最大重试次数,终止任务
return;
}
}
}

View File

@@ -0,0 +1,30 @@
package com.njcn.system.timer.tasks;
import com.njcn.device.pms.api.MonitorSendClient;
import com.njcn.device.pms.pojo.param.MonitorParam;
import com.njcn.system.service.SysDicTreePOService;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
@RequiredArgsConstructor
public class MonitorSendOtherUserTaskRunner implements TimerTaskRunner {
private final MonitorSendClient monitorSendClient;
private final SysDicTreePOService sysDicTreePOService;
@Override
public void action() {
//干扰用户
MonitorParam.Info param4 = new MonitorParam.Info();
param4.setObjType(sysDicTreePOService.queryByCode("2300").getId());
param4.setFiy(true);
monitorSendClient.windSend(param4);
}
}

View File

@@ -0,0 +1,30 @@
package com.njcn.system.timer.tasks;
import com.njcn.device.pms.api.MonitorSendClient;
import com.njcn.device.pms.pojo.param.MonitorParam;
import com.njcn.system.service.SysDicTreePOService;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
@RequiredArgsConstructor
public class MonitorSendPhotovoltaicTaskRunner implements TimerTaskRunner {
private final MonitorSendClient monitorSendClient;
private final SysDicTreePOService sysDicTreePOService;
@Override
public void action() {
//光伏电站
MonitorParam.Info param1 = new MonitorParam.Info();
param1.setObjType(sysDicTreePOService.queryByCode("1402").getId());
param1.setFiy(true);
monitorSendClient.windSend(param1);
}
}

View File

@@ -26,20 +26,5 @@ public class MonitorSendTaskRunner implements TimerTaskRunner {
param.setObjType(sysDicTreePOService.queryByCode("1401").getId());
param.setFiy(true);
monitorSendClient.windSend(param);
//光伏电站
MonitorParam.Info param1 = new MonitorParam.Info();
param1.setObjType(sysDicTreePOService.queryByCode("1402").getId());
param1.setFiy(true);
monitorSendClient.windSend(param1);
//牵引站
MonitorParam.Info param3 = new MonitorParam.Info();
param3.setObjType(sysDicTreePOService.queryByCode("1300").getId());
param3.setFiy(true);
monitorSendClient.windSend(param3);
//干扰用户
MonitorParam.Info param4 = new MonitorParam.Info();
param4.setObjType(sysDicTreePOService.queryByCode("2300").getId());
param4.setFiy(true);
monitorSendClient.windSend(param4);
}
}

View File

@@ -0,0 +1,30 @@
package com.njcn.system.timer.tasks;
import com.njcn.device.pms.api.MonitorSendClient;
import com.njcn.device.pms.pojo.param.MonitorParam;
import com.njcn.system.service.SysDicTreePOService;
import com.njcn.system.timer.TimerTaskRunner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
@RequiredArgsConstructor
public class MonitorSendTractionStationTaskRunner implements TimerTaskRunner {
private final MonitorSendClient monitorSendClient;
private final SysDicTreePOService sysDicTreePOService;
@Override
public void action() {
//牵引站
MonitorParam.Info param3 = new MonitorParam.Info();
param3.setObjType(sysDicTreePOService.queryByCode("1300").getId());
param3.setFiy(true);
monitorSendClient.windSend(param3);
}
}