REM:
1. 修改启动清洗任务响应消息中的expireTime字段,该字段表示为任务结束UTC时间戳(ms)
2. 修改停止清洗任务相关接口的剩余执行时间,修改计算方式
3. 修改loadTaskFromDatabase函数,从数据库中载所有的任务,不单加载新建或者运行的任务
4. 修改expireTime类型为Long
This commit is contained in:
chenlinghy 2020-05-26 17:17:55 +08:00
parent e21a227924
commit b64a3c221e
3 changed files with 18 additions and 16 deletions

View File

@ -38,6 +38,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@ -108,6 +111,7 @@ public class DisposeTaskController {
TaskInfoDetail tf = taskCacheManager.getTaskById(ret.getSecondParam());
rspInfo.setId(String.valueOf(tf.getDeviceId()));
rspInfo.setTaskId(String.valueOf(ret.getSecondParam()));
rspInfo.setExpireTime(convertTimeToLong(tf.getPlanEndTime()));
} else {
log.error("Failed to create task, error:{}", ret.getFirstParam().getMsg());
}
@ -161,8 +165,7 @@ public class DisposeTaskController {
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))/ 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
@ -224,8 +227,7 @@ public class DisposeTaskController {
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))/ 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
@ -287,8 +289,7 @@ public class DisposeTaskController {
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))/ 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
@ -351,8 +352,7 @@ public class DisposeTaskController {
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))/ 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
@ -520,4 +520,10 @@ public class DisposeTaskController {
return ProtocolRespDTO.result(err, rspInfo);
}
}
public static Long convertTimeToLong(String time) {
DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime parse = LocalDateTime.parse(time, ftf);
return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
}

View File

@ -21,5 +21,5 @@ import lombok.NoArgsConstructor;
@JsonPropertyOrder({"id", "taskId", "expireTime", "status", "message"})
public class StartTaskRsp extends IDReturnStatus {
private String taskId;
private int expireTime;
private Long expireTime;
}

View File

@ -81,12 +81,8 @@ public class TaskServiceImpl implements TaskService {
*/
@Override
public void loadTaskFromDatabase() {
// 从数据库中取出所有新建和正在运行的任务
List<TaskInfoDetail> taskList = disposeTaskMapper.selectAll()
.stream()
.filter(v -> v.getType().equals(DisposeTaskStatus.TASK_NEW.getCode())
|| v.getType().equals(DisposeTaskStatus.TASK_RUNNING.getCode()))
.collect(Collectors.toList());
// 从数据库中取出所有任务
List<TaskInfoDetail> taskList = disposeTaskMapper.selectAll();
taskList.forEach(v -> {
if (taskCacheManager.addTask(v) != ErrorCode.ERR_OK) {