parent
00d68ca6b0
commit
126e1d47f4
|
@ -52,4 +52,9 @@ public class GlobalVar {
|
|||
* The constant STRING_HTTP_AUTH_HEAD.
|
||||
*/
|
||||
public static final String STRING_HTTP_AUTH_HEAD = "Bearer ";
|
||||
|
||||
/**
|
||||
* The constant TASK_ERROR_MAX_RETRY.
|
||||
*/
|
||||
public static final int TASK_ERROR_MAX_RETRY = 3;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.dispose.pojo.vo.device.AddNodeReq;
|
|||
import com.dispose.pojo.vo.device.AddNodeRetData;
|
||||
import com.dispose.pojo.vo.device.AddNodeRsp;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
@ -49,6 +50,9 @@ public class DisposeNodeManagerController {
|
|||
@Resource
|
||||
private UserAccountCacheManager userAccountCacheManager;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
/**
|
||||
* Add dispose node protocol resp dto.
|
||||
*
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.dispose.service.impl;
|
|||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
|
@ -85,6 +84,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
List<TaskInfoDetail> taskList = disposeTaskMapper.selectAll();
|
||||
|
||||
taskList.forEach(v -> {
|
||||
v.setRetryTimes(0);
|
||||
if (taskCacheManager.addTask(v) != ErrorCode.ERR_OK) {
|
||||
try {
|
||||
log.error("load error:\n" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.task;
|
|||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.service.TaskService;
|
||||
|
@ -39,6 +40,11 @@ public class TaskManagerTask {
|
|||
while (it.hasNext()) {
|
||||
TaskInfoDetail taskData = it.next();
|
||||
|
||||
// 如果重试次数过多,停止处理该任务
|
||||
if(taskData.getRetryTimes() < GlobalVar.TASK_ERROR_MAX_RETRY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断是否存在正在运行的过期的任务,如果存在则结束该任务
|
||||
if(taskService.taskIsExpired(taskData) && taskService.taskIsRunning(taskData)) {
|
||||
log.info("Finish expired task {}:{} begin at {}",
|
||||
|
@ -53,6 +59,7 @@ public class TaskManagerTask {
|
|||
log.info("Start task {}:{} of {}",
|
||||
taskData.getId(), taskData.getDisposeIp(), taskData.getBeginTime());
|
||||
if (taskService.startTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
taskData.setRetryTimes(taskData.getRetryTimes() + 1);
|
||||
log.error("startTask Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue