diff --git a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/DefaultExecThread.java b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/DefaultExecThread.java index 91c9a89..c73b683 100644 --- a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/DefaultExecThread.java +++ b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/DefaultExecThread.java @@ -446,7 +446,7 @@ public class DefaultExecThread implements AtuExecThread{ RabbitTemplate rabbitTemplate = SpringUtil.getBean(RabbitTemplate.class); rabbitTemplate.convertAndSend(AtuExecConstant.TASK_EXEC_RESULT, JsonUtils.toJson(result)); - if (!AtuExecConstant.TASK_START.equalsIgnoreCase(type)) { + if (!AtuExecConstant.TASK_START.equalsIgnoreCase(type) && !AtuExecConstant.TASK_RETRY.equals(type)) { log.debug("清理正在执行中任务数据"); AtuTaskExecHeartbeatSchedule.execTaskMap.remove(result.getTaskId()); } @@ -741,6 +741,9 @@ public class DefaultExecThread implements AtuExecThread{ if(task.getFailRetryNum()>0){ retry = task.getFailRetryNum()+1; } + if (AtuExecConstant.TASK_RETRY_STRATEGY_PACKAGE.equals(task.getRetryStrategy())) { // 重试策略如果是失败任务打包重试,那么重试次数应该为0,由计划执行完一轮后统一下发 + retry = 1; + } // 创建脚本执行器 this.scriptExecutor = SpringUtils.getBean(ScriptResolutionService.class).getScriptExecutor(task.getTaskId()); if (null == scriptExecutor){ @@ -836,6 +839,8 @@ public class DefaultExecThread implements AtuExecThread{ executeResult.setResultMsg(ae.getMessage()); } executeResult.setResultStatus(2); + // 更新结果到计划服务,新增一条执行记录,用于记录任务重试 + retryExecuteCheck(j + 1 < retry, result, AtuExecConstant.TASK_ASSERT_FAIL); }catch (Exception e) { //执行失败 log.error("第["+j+"]次执行任务执行失败:",e); @@ -847,6 +852,8 @@ public class DefaultExecThread implements AtuExecThread{ executeResult.setResultMsg(msg); } executeResult.setResultStatus(1); + // 更新结果到计划服务,新增一条执行记录,用于记录任务重试 + retryExecuteCheck(j + 1 < retry, result, AtuExecConstant.TASK_ASSERT_FAIL); } } try { @@ -935,6 +942,27 @@ public class DefaultExecThread implements AtuExecThread{ } } + /** + * 单条任务重试检查 + * @param result + */ + private void retryExecuteCheck(boolean forFlag, TaskExecResult result, String resultStatus) { + if (!forFlag) { + return; + } + try { + result.setNeedRetry(true); + if ((task.getRetryStrategy() != null && AtuExecConstant.TASK_RETRY_STRATEGY_SINGLE.equals(task.getRetryStrategy())) || (task.getFailRetryNum() > 0 && StringUtils.isBlank(task.getRetryStrategy()))) { // 单条重试,兼容以前没有但是重试次数不为0 + log.debug("发送信息到平台保存记录,准备重试..."); + updateExecResult(result, resultStatus, ""); + } + } catch (Exception e) { + log.error("新增任务[{}]执行记录失败", task.getTaskId(), e); + } finally { + result.setNeedRetry(false); + } + } + private Script getScriptInfo(String scriptPath){ AtuServerConfig config = SpringUtils.getBean(AtuServerConfig.class); String url = config.getServerUrl() + config.getFileDownloadPath() + scriptPath; diff --git a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/constant/AtuExecConstant.java b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/constant/AtuExecConstant.java index c96ccfd..8bd9b5c 100644 --- a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/constant/AtuExecConstant.java +++ b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/exec/constant/AtuExecConstant.java @@ -16,6 +16,11 @@ public class AtuExecConstant { public static final String TASK_ASSERT_FAIL = "4"; public static final String TASK_CANCEL = "5"; + public static final String TASK_RETRY = "10"; + + public static final String TASK_RETRY_STRATEGY_PACKAGE = "1"; + public static final String TASK_RETRY_STRATEGY_SINGLE = "2"; + /** * 任务结果队列 */ diff --git a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/AutoTask.java b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/AutoTask.java index 1cd5d5b..3dd67b4 100644 --- a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/AutoTask.java +++ b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/AutoTask.java @@ -35,6 +35,11 @@ public class AutoTask { private int failRetryNum; + /** + * 失败重试策略 + */ + private String retryStrategy; + private String appId; private String projectId; @@ -214,4 +219,12 @@ public class AutoTask { public void setEnvId(String envId) { this.envId = envId; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } diff --git a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/TaskExecResult.java b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/TaskExecResult.java index 02b9beb..4a29907 100644 --- a/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/TaskExecResult.java +++ b/cctp-atu/atu-engine/atu-script-engine/src/main/java/net/northking/cctp/se/plan/bean/TaskExecResult.java @@ -27,6 +27,8 @@ public class TaskExecResult { //任务状态 1-开始执行,2-执行成功,3-执行失败,4-断言失败,5-取消,6-超时 private String status; + private boolean needRetry; + private String message; private String currentTime; diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanInfoApiServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanInfoApiServiceImpl.java index 79c4b7d..61beb0c 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanInfoApiServiceImpl.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanInfoApiServiceImpl.java @@ -1160,6 +1160,14 @@ public class AtuPlanInfoApiServiceImpl extends AbstractExcelService entity.setUpdatedBy(NKSecurityContext.getUserId()); entity.setUpdatedTime(new Date()); this.atuPlanInfoService.updatePlanRetryCount(entity); + if (entity.getFailRetry()) { + if (entity.getRetryStrategy() == null) { + entity.setRetryStrategy(PlanConstant.TASK_RETRY_STRATEGY_PACKAGE); + } + } else { + entity.setFailRetryCount(0); + entity.setRetryStrategy(null); + } this.atuPlanInfoService.updateByPrimaryKey(entity); entity.setPrincipalId(planInfo.getPrincipalId()); } else { @@ -1172,6 +1180,9 @@ public class AtuPlanInfoApiServiceImpl extends AbstractExcelService entity.setCreatedTime(new Date()); entity.setUpdatedBy(NKSecurityContext.getUserId()); entity.setUpdatedTime(new Date()); + if (dto.getFailRetry() != null && dto.getFailRetry() && dto.getRetryStrategy() == null) { // 失败重试并且重试策略为空的情况下,默认使用策略:失败任务打包重试 + entity.setRetryStrategy(PlanConstant.TASK_RETRY_STRATEGY_PACKAGE); + } this.atuPlanInfoService.insert(entity); } logger.info("-------------------->保存计划基础信息"); @@ -2635,6 +2646,9 @@ public class AtuPlanInfoApiServiceImpl extends AbstractExcelService if (CollUtil.isEmpty(inputDataList)) { throw new PlatformRuntimeException(ExecPlanError.SCRIPT_INPUT_DATA_IS_NULL); } + if (planInfo.getFailRetry() && PlanConstant.TASK_RETRY_STRATEGY_PACKAGE.equals(planInfo.getRetryStrategy())) { + redisTemplate.opsForHash().put(RedisConstant.PLAN_BATCH_RETRY_COUNT, planBatch.getId(), planInfo.getFailRetryCount()); + } // 异步生成任务 executor.execute(() ->{ boolean hasOfflineDevice = StrUtil.isNotBlank(atuPlanRunDto.getBatchId()); diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanSceneCaseTaskApiServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanSceneCaseTaskApiServiceImpl.java index 93d035f..f91f36d 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanSceneCaseTaskApiServiceImpl.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanSceneCaseTaskApiServiceImpl.java @@ -16,8 +16,10 @@ import net.northking.cctp.executePlan.constants.RedisConstant; import net.northking.cctp.executePlan.db.entity.AtuPlanInfo; import net.northking.cctp.executePlan.db.entity.AtuPlanSceneCaseTask; import net.northking.cctp.executePlan.db.entity.AtuPlanTask; +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; import net.northking.cctp.executePlan.db.service.AtuPlanInfoService; import net.northking.cctp.executePlan.db.service.AtuPlanSceneCaseTaskService; +import net.northking.cctp.executePlan.db.service.AtuPlanTaskRecordService; import net.northking.cctp.executePlan.dto.planBatch.AppPerInfo; import net.northking.cctp.executePlan.dto.planBatch.DevicePerInfo; import net.northking.cctp.executePlan.dto.planBatch.MobileTaskPerformanceDto; @@ -74,6 +76,9 @@ public class AtuPlanSceneCaseTaskApiServiceImpl implements AtuPlanSceneCaseTaskA @Autowired private SimpleStorageService simpleStorageService; + @Autowired + private AtuPlanTaskRecordService planTaskRecordService; + /** * 场景用例处理 * @param taskExecResult 任务执行结果 @@ -228,7 +233,8 @@ public class AtuPlanSceneCaseTaskApiServiceImpl implements AtuPlanSceneCaseTaskA } logger.debug("更新场景任务为结束"); planTaskApiService.updateByPrimaryKey(planTask); - + // 添加任务记录到表atu_plan_task_record + addTaskRecord(taskExecResult, planTask); // 更新批次统计数据 planBatchApiService.updateCacheBatchSumData(planTask); // 删除节点更新时的场景任务文件 @@ -246,6 +252,32 @@ public class AtuPlanSceneCaseTaskApiServiceImpl implements AtuPlanSceneCaseTaskA } } + private void addTaskRecord(AtuTaskExecResultDto taskExecResult, AtuPlanTask planTask) { + try { + planTask.setEndTime(taskExecResult.getCurrentTime()); + + AtuPlanTaskRecord record = new AtuPlanTaskRecord(); + record.setTaskId(planTask.getId()); + // 根据taskId查询执行序号 + long count = planTaskRecordService.count(record); + if (count > 0) { + record.setExecuteType(PlanConstant.TASK_EXECUTE_TYPE_AUTO_RETRY); + } + record.setExecIdx(Math.toIntExact(count) + 1); + // 插入执行任务记录 + record.setId(UUIDUtil.create32UUID()); + record.setStartTime(planTask.getStartTime()); // 任务开始时间 + record.setEndTime(planTask.getEndTime()); // 任务结束时间 + record.setBatchId(planTask.getBatchId()); // 批次 + record.setErrorMsg(taskExecResult.getMessage()); // 任务错误信息 + record.setExecResultFile(taskExecResult.getFilePath()); // 任务执行记录结果文件地址 + record.setVideoUrl(taskExecResult.getVideoPath()); // 任务执行录屏文件地址 + planTaskRecordService.insert(record); + } catch (Exception e) { + logger.error("新增任务记录失败", e); + } + } + /** * 创建下一节点任务 * @param planSceneCaseTask 场景用例节点任务 @@ -297,6 +329,8 @@ public class AtuPlanSceneCaseTaskApiServiceImpl implements AtuPlanSceneCaseTaskA atuTaskExecDto.setScreenRecordSet(planInfo.getScreenRecordSet()); atuTaskExecDto.setScreenshotSet(planInfo.getScreenshotSet()); atuTaskExecDto.setFailRetryNum(planInfo.getFailRetryCount()); + // 重试策略 + atuTaskExecDto.setRetryStrategy(planInfo.getRetryStrategy()); atuTaskExecDto.setAppId(planTaskApiService.queryAppId(planInfo.getId(), nodeInfo.getPlatformType(), nodeInfo.getAppPackage(), nodeInfo.getNodeType())); diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanTaskApiServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanTaskApiServiceImpl.java index 76a7a9d..cb8c86d 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanTaskApiServiceImpl.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/api/service/AtuPlanTaskApiServiceImpl.java @@ -33,10 +33,7 @@ import net.northking.cctp.executePlan.constants.PlanConstant; import net.northking.cctp.executePlan.constants.RabbitConstant; import net.northking.cctp.executePlan.constants.RedisConstant; import net.northking.cctp.executePlan.db.entity.*; -import net.northking.cctp.executePlan.db.service.AtuPlanAppLinkService; -import net.northking.cctp.executePlan.db.service.AtuPlanBatchDeviceLinkService; -import net.northking.cctp.executePlan.db.service.AtuPlanSceneCaseTaskService; -import net.northking.cctp.executePlan.db.service.AtuPlanTaskService; +import net.northking.cctp.executePlan.db.service.*; import net.northking.cctp.executePlan.dto.planBatch.AtuBatchCaseInfoDto; import net.northking.cctp.executePlan.dto.planBatch.AtuExceptionCase; import net.northking.cctp.executePlan.dto.planBatch.BatchRetryDto; @@ -140,6 +137,8 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService @Autowired private RedisTemplate redisTemplate; + @Autowired + private AtuPlanTaskRecordService taskRecordService; @Autowired private EnvNameUtils envNameUtils; @@ -327,9 +326,29 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService } } } + queryTaskExecTake(pagination.getRecords()); return pagination; } + private void queryTaskExecTake(List records) { + try { + if (!records.isEmpty()) { + List ids = records.stream().map(AtuPlanTaskPageDto::getId).collect(Collectors.toList()); + List taskRecords = taskRecordService.queryTotalTake(ids); + if (!taskRecords.isEmpty()) { + Map collectMap = taskRecords.stream().collect(Collectors.toMap(PlanTaskRecordDto::getTaskId, Function.identity())); + for (AtuPlanTaskPageDto record : records) { + if (collectMap.containsKey(record.getId())) { + record.setTotalExecTake(collectMap.get(record.getId()).getTotalTake()); + } + } + } + } + } catch (Exception e) { + logger.error("查询任务的总耗时失败", e); + } + } + @Override public List query(AtuPlanTask atuPlanTask) { return atuPlanTaskService.query(atuPlanTask); @@ -448,6 +467,8 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService String type = planTask.getCaseType(); atuTaskExecDto.setCaseType(type); atuTaskExecDto.setFailRetryNum(batchCaseInfo.getFailRetryCount()); + // 重试策略 + atuTaskExecDto.setRetryStrategy(batchCaseInfo.getRetryStrategy()); boolean deviceOffline = false; if (ObjectUtil.equal(PlanConstant.SCRIPT_TYPE_SCENE, type)) { // 场景用例 @@ -1336,6 +1357,8 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService caseInfoDto.setFailRetryCount(0); if (planInfo.getFailRetry()) { caseInfoDto.setFailRetryCount(planInfo.getFailRetryCount()); + // 重试策略 + caseInfoDto.setRetryStrategy(planInfo.getRetryStrategy()); } // 判断是否场景用例 diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/PlanConstant.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/PlanConstant.java index ecb770c..5826170 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/PlanConstant.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/PlanConstant.java @@ -126,7 +126,30 @@ public class PlanConstant { * 任务超时状态 */ public static final String TASK_TIMEOUT_STATUS = "6"; - + /** + * 任务重试 + */ + public static final String TASK_RETRY_STATUS = "10"; + /** + * 正常执行 + */ + public static final String TASK_EXECUTE_TYPE_NORMAL = "0"; + /** + * 自动重试 + */ + public static final String TASK_EXECUTE_TYPE_AUTO_RETRY = "1"; + /** + * 手动重试 + */ + public static final String TASK_EXECUTE_TYPE_MANUAL_RETRY = "2"; + /** + * 重试策略 :失败任务打包重试 + */ + public static final String TASK_RETRY_STRATEGY_PACKAGE = "1"; + /** + * 重试策略:任务失败立刻重试 + */ + public static final String TASK_RETRY_STRATEGY_SINGLE = "2"; /** * 任务总数key */ diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/RedisConstant.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/RedisConstant.java index c75fc61..8b48653 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/RedisConstant.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/constants/RedisConstant.java @@ -27,6 +27,8 @@ public class RedisConstant { public static final TimeUnit PLAN_BATCH_OFFLINE_DEVICE_TIME_UNIT = TimeUnit.HOURS; + public static final String PLAN_BATCH_RETRY_COUNT = "plan:batch:retry-count:"; + /** * 批次脚本统计数据 */ diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/consumer/TaskExecResultConsumer.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/consumer/TaskExecResultConsumer.java index 17a4197..6506162 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/consumer/TaskExecResultConsumer.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/consumer/TaskExecResultConsumer.java @@ -9,7 +9,9 @@ import net.northking.cctp.executePlan.constants.PlanConstant; import net.northking.cctp.executePlan.constants.RabbitConstant; import net.northking.cctp.executePlan.constants.RedisConstant; import net.northking.cctp.executePlan.db.entity.AtuPlanTask; +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; import net.northking.cctp.executePlan.db.service.AtuPlanInfoService; +import net.northking.cctp.executePlan.db.service.AtuPlanTaskRecordService; import net.northking.cctp.executePlan.db.service.AtuPlanTaskService; import net.northking.cctp.executePlan.dto.planTask.AtuTaskExecResultDto; import org.slf4j.Logger; @@ -57,6 +59,9 @@ public class TaskExecResultConsumer { @Autowired private AtuPlanSceneCaseTaskApiService sceneCaseTaskApiService; + @Autowired + private AtuPlanTaskRecordService taskRecordService; + @PostConstruct public void init(){ // 初始化队列并绑定到交换机 @@ -120,12 +125,25 @@ public class TaskExecResultConsumer { atuPlanInfoService.updatePlanByLastBatchId(planTask.getBatchId(), PlanConstant.PLAN_EXECUTING_STATUS); } + }else if(taskExecResult.isNeedRetry()) { // 任务需要失败后需要重试 + // 添加任务执行记录 + addTaskRecord(taskExecResult, planTask); + + // 任务重试,结束时间作为重试的开始时间 + AtuPlanTask updateTaskTime = new AtuPlanTask(); + updateTaskTime.setId(planTask.getId()); + updateTaskTime.setStartTime(taskExecResult.getCurrentTime()); + planTaskService.updateByPrimaryKey(updateTaskTime); + // 结束 + return; }else{ planTask.setStatus(taskExecResult.getStatus()); planTask.setEndTime(taskExecResult.getCurrentTime()); planTask.setErrorMsg(taskExecResult.getMessage()); planTask.setVideoUrl(taskExecResult.getVideoPath()); planTask.setExecResultFile(taskExecResult.getFilePath()); + // 任务完成后查询数据后将数据插入到表atu_plan_task_record + addTaskRecord(taskExecResult, planTask); } if (PlanConstant.SCRIPT_TYPE_ANDROID.equals(planTask.getCaseType()) @@ -153,5 +171,32 @@ public class TaskExecResultConsumer { logger.error("任务结果更新失败", e); } } + + private void addTaskRecord(AtuTaskExecResultDto taskExecResult, AtuPlanTask planTask) { + try { + planTask.setEndTime(taskExecResult.getCurrentTime()); + + AtuPlanTaskRecord record = new AtuPlanTaskRecord(); + record.setTaskId(planTask.getId()); + // 根据taskId查询执行序号 + long count = taskRecordService.count(record); + if (count > 0) { + record.setExecuteType(PlanConstant.TASK_EXECUTE_TYPE_AUTO_RETRY); + } + record.setExecIdx(Math.toIntExact(count) + 1); + // 插入执行任务记录 + record.setId(UUIDUtil.create32UUID()); + record.setStartTime(planTask.getStartTime()); // 任务开始时间 + record.setEndTime(planTask.getEndTime()); // 任务结束时间 + record.setStatus(taskExecResult.getStatus()); // 执行结果 + record.setBatchId(planTask.getBatchId()); // 批次 + record.setErrorMsg(taskExecResult.getMessage()); // 任务错误信息 + record.setExecResultFile(taskExecResult.getFilePath()); // 任务执行记录结果文件地址 + record.setVideoUrl(taskExecResult.getVideoPath()); // 任务执行录屏文件地址 + taskRecordService.insert(record); + } catch (Exception e) { + logger.error("新增任务记录失败", e); + } + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskDao.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskDao.java index b592104..9697fdb 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskDao.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskDao.java @@ -65,6 +65,12 @@ public interface AtuPlanTaskDao extends AtuPlanTaskMapper */ Long queryBatchFirstTaskStartTime(String batchId); + /** + * 根据批次ID查询该批次失败的任务ID集合 + * @param batchId 批次ID + * @return 失败任务ID集合 + */ + List queryAllFailIdList(String batchId); List selectCaseListByBatchId(String batchId); diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskRecordDao.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskRecordDao.java new file mode 100644 index 0000000..4912b26 --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/dao/AtuPlanTaskRecordDao.java @@ -0,0 +1,28 @@ +/* +* Copyright (c) 京北方信息技术股份有限公司 Corporation 2024 . All rights reserved. +* +*/ +package net.northking.cctp.executePlan.db.dao; + +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; +import net.northking.cctp.executePlan.db.mapper.AtuPlanTaskRecordMapper; +import net.northking.cctp.executePlan.dto.planTask.PlanTaskRecordDto; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * Mybatis数据库持久层(业务层):任务执行记录表 + * + *

文件内容由代码生成器产生,请不要手动修改!
+ * createdate: 2024-10-16 17:02:48
+ * @author: maven-cctp-plugin
+ * @since: 1.0
+ */ +@Repository +public interface AtuPlanTaskRecordDao extends AtuPlanTaskRecordMapper +{ + List queryTotalTake(@Param("taskIds") List taskIds); + +} diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanInfo.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanInfo.java index 68916a6..e0a08c0 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanInfo.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanInfo.java @@ -175,6 +175,11 @@ public class AtuPlanInfo extends TenantPartition implements Entity */ @ApiModelProperty("失败重试次数") private Integer failRetryCount; + /** + * 失败重试策略
+ */ + @ApiModelProperty("重试策略") + private String retryStrategy; /** * 是否失败生成计划;0-否,1-是
*/ @@ -1009,4 +1014,11 @@ public class AtuPlanInfo extends TenantPartition implements Entity { } + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanTaskRecord.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanTaskRecord.java new file mode 100644 index 0000000..5e4160f --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/entity/AtuPlanTaskRecord.java @@ -0,0 +1,303 @@ +/* +* Copyright (c) 京北方信息技术股份有限公司 Corporation 2024 . All rights reserved. +* +*/ +package net.northking.cctp.executePlan.db.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; + +import net.northking.cctp.common.db.POJO; +import net.northking.cctp.common.db.Partition; +import net.northking.cctp.common.db.entity.Entity; +import net.northking.cctp.common.validation.ValAddGroup; +import net.northking.cctp.common.validation.ValUpdateGroup; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +/** + * 任务执行记录表 + * + *

文件内容由代码生成器产生,请不要手动修改!
+ * createdate: 2024-10-16 17:02:48
+ * @author: maven-cctp-plugin
+ * @since: 1.0
+ */ +@ApiModel(description = "任务执行记录表") +public class AtuPlanTaskRecord extends Partition implements POJO +{ + public static final String KEY_id = "id"; + public static final String KEY_taskId = "taskId"; + public static final String KEY_batchId = "batchId"; + public static final String KEY_execIdx = "execIdx"; + public static final String KEY_startTime = "startTime"; + public static final String KEY_endTime = "endTime"; + public static final String KEY_executeType = "executeType"; + public static final String KEY_status = "status"; + public static final String KEY_errorMsg = "errorMsg"; + public static final String KEY_videoUrl = "videoUrl"; + public static final String KEY_execResultFile = "execResultFile"; + + /** + * 记录id
+ */ + @ApiModelProperty("记录id") + @Size(max = 32, message="记录id-id: 数据长度不能 > 32" ) + private String id; + /** + * 任务id
+ */ + @ApiModelProperty("任务id") + @Size(max = 32, message="任务id-taskId: 数据长度不能 > 32" ) + private String taskId; + /** + * 批次id
+ */ + @ApiModelProperty("批次id") + @Size(max = 32, message="批次id-batchId: 数据长度不能 > 32" ) + private String batchId; + /** + * 执行序号
+ */ + @ApiModelProperty("执行序号") + private Integer execIdx; + /** + * 开始时间
+ */ + @ApiModelProperty("开始时间") + private Long startTime; + /** + * 结束时间
+ */ + @ApiModelProperty("结束时间") + private Long endTime; + /** + * 执行类型,0-正常执行|1-自动重试|2-手动重试
+ */ + @ApiModelProperty("执行类型,0-正常执行|1-自动重试|2-手动重试") + @Size(max = 10, message="执行类型,0-正常执行|1-自动重试|2-手动重试-executeType: 数据长度不能 > 10" ) + private String executeType; + /** + * 状态
+ */ + @ApiModelProperty("状态") + @Size(max = 10, message="状态-status: 数据长度不能 > 10" ) + private String status; + /** + * 错误信息
+ */ + @ApiModelProperty("错误信息") + @Size(max = 65535, message="错误信息-errorMsg: 数据长度不能 > 65535" ) + private String errorMsg; + /** + * 视频地址
+ */ + @ApiModelProperty("视频地址") + @Size(max = 255, message="视频地址-videoUrl: 数据长度不能 > 255" ) + private String videoUrl; + /** + * 执行结果文件
+ */ + @ApiModelProperty("执行结果文件") + @Size(max = 255, message="执行结果文件-execResultFile: 数据长度不能 > 255" ) + private String execResultFile; + + /** + * 记录id
+ */ + public String getId() + { + return id; + } + + /** + * 记录id
+ * + * @param id 记录id + */ + public void setId(String id) + { + this.id = id; + } + /** + * 任务id
+ */ + public String getTaskId() + { + return taskId; + } + + /** + * 任务id
+ * + * @param taskId 任务id + */ + public void setTaskId(String taskId) + { + this.taskId = taskId; + } + /** + * 批次id
+ */ + public String getBatchId() + { + return batchId; + } + + /** + * 批次id
+ * + * @param batchId 批次id + */ + public void setBatchId(String batchId) + { + this.batchId = batchId; + } + /** + * 执行序号
+ */ + public Integer getExecIdx() + { + return execIdx; + } + + /** + * 执行序号
+ * + * @param execIdx 执行序号 + */ + public void setExecIdx(Integer execIdx) + { + this.execIdx = execIdx; + } + /** + * 开始时间
+ */ + public Long getStartTime() + { + return startTime; + } + + /** + * 开始时间
+ * + * @param startTime 开始时间 + */ + public void setStartTime(Long startTime) + { + this.startTime = startTime; + } + /** + * 结束时间
+ */ + public Long getEndTime() + { + return endTime; + } + + /** + * 结束时间
+ * + * @param endTime 结束时间 + */ + public void setEndTime(Long endTime) + { + this.endTime = endTime; + } + /** + * 执行类型,0-正常执行|1-自动重试|2-手动重试
+ */ + public String getExecuteType() + { + return executeType; + } + + /** + * 执行类型,0-正常执行|1-自动重试|2-手动重试
+ * + * @param executeType 执行类型,0-正常执行|1-自动重试|2-手动重试 + */ + public void setExecuteType(String executeType) + { + this.executeType = executeType; + } + /** + * 状态
+ */ + public String getStatus() + { + return status; + } + + /** + * 状态
+ * + * @param status 状态 + */ + public void setStatus(String status) + { + this.status = status; + } + /** + * 错误信息
+ */ + public String getErrorMsg() + { + return errorMsg; + } + + /** + * 错误信息
+ * + * @param errorMsg 错误信息 + */ + public void setErrorMsg(String errorMsg) + { + this.errorMsg = errorMsg; + } + /** + * 视频地址
+ */ + public String getVideoUrl() + { + return videoUrl; + } + + /** + * 视频地址
+ * + * @param videoUrl 视频地址 + */ + public void setVideoUrl(String videoUrl) + { + this.videoUrl = videoUrl; + } + /** + * 执行结果文件
+ */ + public String getExecResultFile() + { + return execResultFile; + } + + /** + * 执行结果文件
+ * + * @param execResultFile 执行结果文件 + */ + public void setExecResultFile(String execResultFile) + { + this.execResultFile = execResultFile; + } + + public AtuPlanTaskRecord() + { + } + +} diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskRecordServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskRecordServiceImpl.java new file mode 100644 index 0000000..5c1c49a --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskRecordServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 京北方信息技术股份有限公司 Corporation 2024 . All rights reserved. + * + */ +package net.northking.cctp.executePlan.db.impl; + +import net.northking.cctp.executePlan.db.dao.AtuPlanTaskRecordDao; +import net.northking.cctp.executePlan.db.service.AtuPlanTaskRecordService; +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; + +import net.northking.cctp.common.db.BasicDao; +import net.northking.cctp.common.db.PaginationService; + +import net.northking.cctp.executePlan.dto.planTask.PlanTaskRecordDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Service; + +import java.util.List; + + +/** + * 任务执行记录表 + * + *

文件内容由代码生成器产生,请不要手动修改!
+ * createdate: 2024-10-16 17:02:48
+ * + * @author: maven-cctp-plugin
+ * @since: 1.0
+ */ +@Service +@ConditionalOnMissingBean(name = "AtuPlanTaskRecordServiceImpl") +public class AtuPlanTaskRecordServiceImpl extends PaginationService implements AtuPlanTaskRecordService { + private static final Logger logger = LoggerFactory.getLogger(AtuPlanTaskRecordServiceImpl.class); + + private final AtuPlanTaskRecordDao atuPlanTaskRecordDao; + + public AtuPlanTaskRecordServiceImpl(AtuPlanTaskRecordDao atuPlanTaskRecordDao) { + this.atuPlanTaskRecordDao = atuPlanTaskRecordDao; + } + + public BasicDao getDao() { + return atuPlanTaskRecordDao; + } + + public AtuPlanTaskRecord createEntity() { + return new AtuPlanTaskRecord(); + } + + @Override + protected void beforeInsert(AtuPlanTaskRecord record) { + + } + + @Override + protected void beforeUpdate(AtuPlanTaskRecord record) { + + } + + // ---- The End by Generator ----// + @Override + public List queryTotalTake(List ids) { + return atuPlanTaskRecordDao.queryTotalTake(ids); + } + + +} + diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskServiceImpl.java index dfb2fd4..693e054 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskServiceImpl.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/impl/AtuPlanTaskServiceImpl.java @@ -87,6 +87,10 @@ private static final Logger logger = LoggerFactory.getLogger(AtuPlanTaskServiceI return atuPlanTaskDao.queryBatchFirstTaskStartTime(batchId); } + @Override + public List queryAllFailIdList(String batchId) { + return atuPlanTaskDao.queryAllFailIdList(batchId); + } @Override diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/mapper/AtuPlanTaskRecordServiceImpl.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/mapper/AtuPlanTaskRecordServiceImpl.java new file mode 100644 index 0000000..87902f7 --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/mapper/AtuPlanTaskRecordServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 京北方信息技术股份有限公司 Corporation 2024 . All rights reserved. + * + */ +package net.northking.cctp.executePlan.db.mapper; + +import net.northking.cctp.executePlan.db.dao.AtuPlanTaskRecordDao; +import net.northking.cctp.executePlan.db.service.AtuPlanTaskRecordService; +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; + +import net.northking.cctp.common.db.BasicDao; +import net.northking.cctp.common.db.PaginationService; + +import net.northking.cctp.executePlan.dto.planTask.PlanTaskRecordDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Service; + +import java.util.List; + + +/** + * 任务执行记录表 + * + *

文件内容由代码生成器产生,请不要手动修改!
+ * createdate: 2024-10-16 17:02:48
+ * + * @author: maven-cctp-plugin
+ * @since: 1.0
+ */ +@Service +@ConditionalOnMissingBean(name = "AtuPlanTaskRecordServiceImpl") +public class AtuPlanTaskRecordServiceImpl extends PaginationService implements AtuPlanTaskRecordService { + private static final Logger logger = LoggerFactory.getLogger(AtuPlanTaskRecordServiceImpl.class); + + private final AtuPlanTaskRecordDao atuPlanTaskRecordDao; + + public AtuPlanTaskRecordServiceImpl(AtuPlanTaskRecordDao atuPlanTaskRecordDao) { + this.atuPlanTaskRecordDao = atuPlanTaskRecordDao; + } + + public BasicDao getDao() { + return atuPlanTaskRecordDao; + } + + public AtuPlanTaskRecord createEntity() { + return new AtuPlanTaskRecord(); + } + + @Override + protected void beforeInsert(AtuPlanTaskRecord record) { + + } + + @Override + protected void beforeUpdate(AtuPlanTaskRecord record) { + + } + + // ---- The End by Generator ----// + @Override + public List queryTotalTake(List ids) { + return atuPlanTaskRecordDao.queryTotalTake(ids); + } + + +} + diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskRecordService.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskRecordService.java new file mode 100644 index 0000000..e570538 --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskRecordService.java @@ -0,0 +1,28 @@ +/* +* Copyright (c) 京北方信息技术股份有限公司 Corporation 2024 . All rights reserved. +* +*/ +package net.northking.cctp.executePlan.db.service; + +import net.northking.cctp.common.db.BasicService; +import net.northking.cctp.executePlan.db.entity.AtuPlanTaskRecord; +import net.northking.cctp.executePlan.dto.planTask.PlanTaskRecordDto; + +import java.util.List; + +/** + * 任务执行记录表 + * + *

文件内容由代码生成器产生,请不要手动修改!
+ * createdate: 2024-10-16 17:02:48
+ * @author: maven-cctp-plugin
+ * @since: 1.0
+ */ +public interface AtuPlanTaskRecordService extends BasicService +{ + + + +// ---- The End by Generator ----// + List queryTotalTake(List ids); +} diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskService.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskService.java index 49fa74b..ef94b29 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskService.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/db/service/AtuPlanTaskService.java @@ -62,6 +62,12 @@ public interface AtuPlanTaskService extends BasicService */ Long queryBatchFirstTaskStartTime(String batchId); + /** + * 根据批次ID查询该批次失败的任务ID集合 + * @param batchId 批次ID + * @return 失败任务ID集合 + */ + List queryAllFailIdList(String batchId); List queryCaseListByBatchId(String batchId); diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planBatch/BatchStrategyDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planBatch/BatchStrategyDto.java index 2ccd68c..aead898 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planBatch/BatchStrategyDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planBatch/BatchStrategyDto.java @@ -53,6 +53,11 @@ public class BatchStrategyDto implements Serializable { */ private Integer failRetryCount = 0; + /** + * 失败重试策略 + */ + private String retryStrategy; + public String getTenantId() { return tenantId; } @@ -116,4 +121,12 @@ public class BatchStrategyDto implements Serializable { public void setFailRetryCount(Integer failRetryCount) { this.failRetryCount = failRetryCount; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoAddDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoAddDto.java index 31fb61a..3f67ad4 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoAddDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoAddDto.java @@ -112,6 +112,11 @@ public class AtuPlanInfoAddDto implements Serializable */ @ApiModelProperty("失败重试次数") private Integer failRetryCount; + /** + * 失败重试策略
+ */ + @ApiModelProperty("重试策略") + private String retryStrategy; /** * 是否失败生成计划;0-否,1-是
*/ @@ -338,4 +343,12 @@ public class AtuPlanInfoAddDto implements Serializable public void setDeviceList(List deviceList) { this.deviceList = deviceList; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoDetailDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoDetailDto.java index f0a5817..837dad9 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoDetailDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoDetailDto.java @@ -147,6 +147,11 @@ public class AtuPlanInfoDetailDto implements Serializable */ @ApiModelProperty("失败重试次数") private Integer failRetryCount; + /** + * 失败重试策略
+ */ + @ApiModelProperty("重试策略") + private String retryStrategy; /** * 是否失败生成计划;0-否,1-是
*/ @@ -636,4 +641,12 @@ public class AtuPlanInfoDetailDto implements Serializable public void setLastBatchScriptSumMap(Map lastBatchScriptSumMap) { this.lastBatchScriptSumMap = lastBatchScriptSumMap; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoUpdateDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoUpdateDto.java index 466b5f1..7ca45e3 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoUpdateDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planInfo/AtuPlanInfoUpdateDto.java @@ -115,6 +115,11 @@ public class AtuPlanInfoUpdateDto implements Serializable */ @ApiModelProperty("失败重试次数") private Integer failRetryCount; + /** + * 失败重试策略
+ */ + @ApiModelProperty("重试策略") + private String retryStrategy; /** * 是否失败生成计划;0-否,1-是
*/ @@ -357,4 +362,12 @@ public class AtuPlanInfoUpdateDto implements Serializable public void setDeviceList(List deviceList) { this.deviceList = deviceList; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuPlanTaskPageDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuPlanTaskPageDto.java index b040a41..6431abf 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuPlanTaskPageDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuPlanTaskPageDto.java @@ -180,6 +180,9 @@ public class AtuPlanTaskPageDto implements Serializable { @ApiModelProperty("当前直播是否为接口用例") private boolean apiCase = false; + @ApiModelProperty("总耗时") + private Long totalExecTake; + public boolean isApiCase() { return apiCase; } @@ -395,4 +398,12 @@ public class AtuPlanTaskPageDto implements Serializable { public void setKeyword(String keyword) { this.keyword = keyword; } + + public Long getTotalExecTake() { + return totalExecTake; + } + + public void setTotalExecTake(Long totalExecTake) { + this.totalExecTake = totalExecTake; + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecDto.java index 50f6ba2..9dcd239 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecDto.java @@ -77,7 +77,10 @@ public class AtuTaskExecDto implements Serializable { * 失败重试次数 */ private Integer failRetryNum; - + /** + * 失败重试策略
+ */ + private String retryStrategy; /** * 应用ID */ @@ -207,4 +210,12 @@ public class AtuTaskExecDto implements Serializable { public void setEnvId(String envId) { this.envId = envId; } + + public String getRetryStrategy() { + return retryStrategy; + } + + public void setRetryStrategy(String retryStrategy) { + this.retryStrategy = retryStrategy; + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecResultDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecResultDto.java index b02e68d..e6ad334 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecResultDto.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/AtuTaskExecResultDto.java @@ -46,6 +46,10 @@ public class AtuTaskExecResultDto implements Serializable { * 任务状态 1-开始执行,2-执行成功,3-执行失败,4-断言失败,5-取消,6-超时 */ private String status; + /** + * 是否要重试 + */ + private boolean needRetry; /** * 执行信息 @@ -224,4 +228,12 @@ public class AtuTaskExecResultDto implements Serializable { public void setDevicePerInfo(DevicePerInfo devicePerInfo) { this.devicePerInfo = devicePerInfo; } + + public boolean isNeedRetry() { + return needRetry; + } + + public void setNeedRetry(boolean needRetry) { + this.needRetry = needRetry; + } } diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/PlanTaskRecordDto.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/PlanTaskRecordDto.java new file mode 100644 index 0000000..a7c3b56 --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/dto/planTask/PlanTaskRecordDto.java @@ -0,0 +1,24 @@ +package net.northking.cctp.executePlan.dto.planTask; + +public class PlanTaskRecordDto { + + private String taskId; + + private long totalTake; + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public long getTotalTake() { + return totalTake; + } + + public void setTotalTake(long totalTake) { + this.totalTake = totalTake; + } +} diff --git a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/job/PlanBatchTaskDataUpdateJob.java b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/job/PlanBatchTaskDataUpdateJob.java index c78b475..3e9b6a0 100644 --- a/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/job/PlanBatchTaskDataUpdateJob.java +++ b/cctp-atu/atu-execute-plan/src/main/java/net/northking/cctp/executePlan/job/PlanBatchTaskDataUpdateJob.java @@ -13,6 +13,7 @@ import net.northking.cctp.common.s3.NKFile; import net.northking.cctp.common.s3.SimpleStorageService; import net.northking.cctp.common.security.authentication.NKSecurityContext; import net.northking.cctp.executePlan.api.service.AtuPlanInfoApiService; +import net.northking.cctp.executePlan.api.service.AtuPlanTaskApiService; import net.northking.cctp.executePlan.api.service.MessageCenterService; import net.northking.cctp.executePlan.api.third.feilang.service.FeiLangService; import net.northking.cctp.executePlan.constants.MsgConstant; @@ -21,10 +22,7 @@ import net.northking.cctp.executePlan.constants.RabbitConstant; import net.northking.cctp.executePlan.constants.RedisConstant; import net.northking.cctp.executePlan.db.entity.*; import net.northking.cctp.executePlan.db.service.*; -import net.northking.cctp.executePlan.dto.planBatch.AtuPlanBatchDetailDto; -import net.northking.cctp.executePlan.dto.planBatch.BatchAppInfoDto; -import net.northking.cctp.executePlan.dto.planBatch.BatchMobilePerformanceDto; -import net.northking.cctp.executePlan.dto.planBatch.MobileTaskPerformanceDto; +import net.northking.cctp.executePlan.dto.planBatch.*; import net.northking.cctp.executePlan.dto.planInfo.AtuPlanRunDto; import net.northking.cctp.executePlan.enums.MobilePlatformEnum; import net.northking.cctp.executePlan.feign.PublicFeignClient; @@ -68,6 +66,9 @@ public class PlanBatchTaskDataUpdateJob { @Autowired private AtuPlanTaskService planTaskService; + @Autowired + private AtuPlanTaskApiService planTaskApiService; + @Autowired private AtuPlanInfoApiService planInfoApiService; @@ -267,6 +268,41 @@ public class PlanBatchTaskDataUpdateJob { logger.debug("同步缓存中计划批次统计数据----end----"); } + /** + * 失败重试检查 + * @param planInfo 计划信息 + * @param planBatch 批次信息 + * @return 是否需要重试 + */ + private boolean failRetryCheck(AtuPlanInfo planInfo, AtuPlanBatch planBatch) { + if (planInfo.getFailRetry() && PlanConstant.TASK_RETRY_STRATEGY_PACKAGE.equals(planInfo.getRetryStrategy())) { + Object o = redisTemplate.opsForHash().get(RedisConstant.PLAN_BATCH_RETRY_COUNT, planBatch.getId()); + if (o != null) { + int count = Integer.parseInt(o.toString()); + logger.info("计划-批次【{}-{}】重试次数还剩下:{}次", planInfo.getPlanName(), planBatch.getBatch(), count); + if (count == 0) { // 重试已完成 + redisTemplate.opsForHash().delete(RedisConstant.PLAN_BATCH_RETRY_COUNT, planBatch.getId()); + return false; + } + // 查询批次下的失败任务 + List taskIds = planTaskService.queryAllFailIdList(planBatch.getId()); + List resultIds = new ArrayList<>(taskIds); + BatchRetryDto dto = new BatchRetryDto(); + dto.setTaskIdList(resultIds); + logger.info("计划-批次【{}-{}】需要重试的任务数量:{}", planInfo.getPlanName(), planBatch.getBatch(), taskIds.size()); + if (!taskIds.isEmpty()) { + planTaskApiService.taskRetry(dto); + redisTemplate.opsForHash().put(RedisConstant.PLAN_BATCH_RETRY_COUNT, planBatch.getId(), String.valueOf(--count)); + } else { + redisTemplate.opsForHash().delete(RedisConstant.PLAN_BATCH_RETRY_COUNT, planBatch.getId()); // 没有失败的任务,清除redis信息,不需要重试 + return false; + } + return true; + } + } + return false; + } + private void saveDevicePerData(AtuPlanBatchDetailDto atuPlanBatchDetailDto) { String batchId = atuPlanBatchDetailDto.getId(); String tenantId = atuPlanBatchDetailDto.getTenantId(); @@ -459,6 +495,22 @@ public class PlanBatchTaskDataUpdateJob { * @param planBatch 批次信息 */ private void handleEnd(AtuPlanInfo planInfo, AtuPlanBatchDetailDto planBatch) { + if (PlanConstant.BATCH_CANCEL_STATUS.equals(planBatch.getStatus())) { // 如果是取消,不需要执行收尾处理 + return; + } + // 检查计划是否需要重试,如果需要并且是执行完成批次后再执行失败的任务,那么获取失败任务,批量重试。 + if (PlanConstant.BATCH_FINISH_STATUS.equals(planBatch.getStatus()) && planInfo.getFailRetry()) { + boolean isRetry = false; + try { + isRetry = failRetryCheck(planInfo, planBatch); + } catch (Exception e) { + logger.error("批次{}下失败任务重试失败", planBatch.getId(), e); + } + if (isRetry) { + logger.info("计划需要对失败的任务进行重试..."); + return; + } + } // 计划是否被其他计划设为前置执行计划 List planIdList = planInfoService.queryFollowUpPlanIdList(planInfo.getId()); if (CollUtil.isNotEmpty(planIdList)) { diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanInfo.Mapper.xml b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanInfo.Mapper.xml index d05e992..e797590 100644 --- a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanInfo.Mapper.xml +++ b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanInfo.Mapper.xml @@ -45,6 +45,8 @@ + + @@ -109,6 +111,7 @@ ,mail_address ,is_fail_retry ,fail_retry_count + ,retry_strategy ,is_fail_create_plan ,last_exec_time ,next_exec_time @@ -363,6 +366,9 @@ fail_retry_count, + + retry_strategy, + is_fail_create_plan, @@ -482,6 +488,9 @@ #{failRetry, jdbcType=BIT}, + + #{retryStrategy, jdbcType=VARCHAR}, + #{failRetryCount, jdbcType=INTEGER}, @@ -574,6 +583,7 @@ mail_address, is_fail_retry, fail_retry_count, + retry_strategy, is_fail_create_plan, last_exec_time, next_exec_time, @@ -618,6 +628,7 @@ #{item.mailAddress, jdbcType=VARCHAR}, #{item.failRetry, jdbcType=BIT}, #{item.failRetryCount, jdbcType=INTEGER}, + #{item.retryStrategy, jdbcType=VARCHAR}, #{item.failCreatePlan, jdbcType=BIT}, #{item.lastExecTime, jdbcType=TIMESTAMP}, #{item.nextExecTime, jdbcType=TIMESTAMP}, @@ -701,6 +712,9 @@ fail_retry_count = #{failRetryCount, jdbcType=INTEGER}, + + retry_strategy = #{retryStrategy, jdbcType=VARCHAR}, + is_fail_create_plan = #{failCreatePlan, jdbcType=BIT}, @@ -831,6 +845,9 @@ AND fail_retry_count = #{failRetryCount,jdbcType=INTEGER} + + AND retry_strategy=#{retryStrategy,jdbcType=VARCHAR} + AND is_fail_create_plan = #{failCreatePlan,jdbcType=BIT} @@ -958,6 +975,9 @@ AND fail_retry_count=#{failRetryCount,jdbcType=INTEGER} + + AND retry_strategy=#{retryStrategy,jdbcType=VARCHAR} + AND is_fail_create_plan=#{failCreatePlan,jdbcType=BIT} diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanTaskRecord.Mapper.xml b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanTaskRecord.Mapper.xml new file mode 100644 index 0000000..f615b1a --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/base/AtuPlanTaskRecord.Mapper.xml @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + ,task_id + ,batch_id + ,exec_idx + ,start_time + ,end_time + ,execute_type + ,status + ,error_msg + ,video_url + ,exec_result_file + + + + ${defaultSchema}.atu_plan_task_record + + + + + + + + delete from + + where id = #{id,jdbcType=VARCHAR} + + + + delete from + + where id in + + #{idItem, jdbcType=VARCHAR} + + + + + delete from + + + + + id = #{id,jdbcType=VARCHAR} + + + + AND id=#{id,jdbcType=VARCHAR} + + + AND task_id=#{taskId,jdbcType=VARCHAR} + + + AND batch_id=#{batchId,jdbcType=VARCHAR} + + + AND exec_idx=#{execIdx,jdbcType=INTEGER} + + + AND start_time=#{startTime,jdbcType=BIGINT} + + + AND end_time=#{endTime,jdbcType=BIGINT} + + + AND execute_type=#{executeType,jdbcType=VARCHAR} + + + AND status=#{status,jdbcType=VARCHAR} + + + AND error_msg=#{errorMsg,jdbcType=LONGVARCHAR} + + + AND video_url=#{videoUrl,jdbcType=VARCHAR} + + + AND exec_result_file=#{execResultFile,jdbcType=VARCHAR} + + + + + + insert into + + + + id, + + + task_id, + + + batch_id, + + + exec_idx, + + + start_time, + + + end_time, + + + execute_type, + + + status, + + + error_msg, + + + video_url, + + + exec_result_file, + + + + + #{id, jdbcType=VARCHAR}, + + + #{taskId, jdbcType=VARCHAR}, + + + #{batchId, jdbcType=VARCHAR}, + + + #{execIdx, jdbcType=INTEGER}, + + + #{startTime, jdbcType=BIGINT}, + + + #{endTime, jdbcType=BIGINT}, + + + #{executeType, jdbcType=VARCHAR}, + + + #{status, jdbcType=VARCHAR}, + + + #{errorMsg, jdbcType=LONGVARCHAR}, + + + #{videoUrl, jdbcType=VARCHAR}, + + + #{execResultFile, jdbcType=VARCHAR}, + + + + + + insert into + + + id, + task_id, + batch_id, + exec_idx, + start_time, + end_time, + execute_type, + status, + error_msg, + video_url, + exec_result_file, + + values + + + #{item.id, jdbcType=VARCHAR}, + #{item.taskId, jdbcType=VARCHAR}, + #{item.batchId, jdbcType=VARCHAR}, + #{item.execIdx, jdbcType=INTEGER}, + #{item.startTime, jdbcType=BIGINT}, + #{item.endTime, jdbcType=BIGINT}, + #{item.executeType, jdbcType=VARCHAR}, + #{item.status, jdbcType=VARCHAR}, + #{item.errorMsg, jdbcType=LONGVARCHAR}, + #{item.videoUrl, jdbcType=VARCHAR}, + #{item.execResultFile, jdbcType=VARCHAR}, + + + + + + update + + + + task_id = #{taskId, jdbcType=VARCHAR}, + + + batch_id = #{batchId, jdbcType=VARCHAR}, + + + exec_idx = #{execIdx, jdbcType=INTEGER}, + + + start_time = #{startTime, jdbcType=BIGINT}, + + + end_time = #{endTime, jdbcType=BIGINT}, + + + execute_type = #{executeType, jdbcType=VARCHAR}, + + + status = #{status, jdbcType=VARCHAR}, + + + error_msg = #{errorMsg, jdbcType=LONGVARCHAR}, + + + video_url = #{videoUrl, jdbcType=VARCHAR}, + + + exec_result_file = #{execResultFile, jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + + + + + \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanInfo.Dao.xml b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanInfo.Dao.xml index cdb0dbf..d49daa0 100644 --- a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanInfo.Dao.xml +++ b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanInfo.Dao.xml @@ -49,6 +49,8 @@ + + @@ -130,6 +132,7 @@ ,mail_address ,is_fail_retry ,fail_retry_count + ,retry_strategy ,is_fail_create_plan ,last_exec_time ,next_exec_time @@ -210,6 +213,9 @@ AND fail_retry_count = #{failRetryCount,jdbcType=INTEGER} + + AND retry_strategy = #{retryStrategy,jdbcType=VARCHAR} + AND is_fail_create_plan = #{failCreatePlan,jdbcType=BIT} @@ -288,6 +294,7 @@ ,mail_address ,is_fail_retry ,fail_retry_count + ,retry_strategy ,is_fail_create_plan ,last_exec_time ,next_exec_time @@ -418,6 +425,7 @@ ,mail_address ,is_fail_retry ,fail_retry_count + ,retry_strategy ,is_fail_create_plan ,last_exec_time ,next_exec_time diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTask.Dao.xml b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTask.Dao.xml index 59ebe38..a383cce 100644 --- a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTask.Dao.xml +++ b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTask.Dao.xml @@ -329,4 +329,8 @@ where batch_id in (select id from atu_plan_batch where plan_id = #{planId}) LIMIT #{num} + + \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTaskRecord.Dao.xml b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTaskRecord.Dao.xml new file mode 100644 index 0000000..b1ae418 --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/resources/mybatis/ext/AtuPlanTaskRecord.Dao.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cctp-atu/atu-execute-plan/src/main/resources/mysql/ddl.sql b/cctp-atu/atu-execute-plan/src/main/resources/mysql/ddl.sql new file mode 100644 index 0000000..5eac57f --- /dev/null +++ b/cctp-atu/atu-execute-plan/src/main/resources/mysql/ddl.sql @@ -0,0 +1,22 @@ +-- 2024.10.17 增加表:atu_plan_task_record +CREATE TABLE `atu_plan_task_record` ( + `id` VARCHAR(32) NOT NULL COMMENT '记录id' COLLATE 'utf8mb4_general_ci', + `task_id` VARCHAR(32) NULL DEFAULT NULL COMMENT '任务id' COLLATE 'utf8mb4_general_ci', + `batch_id` VARCHAR(32) NULL DEFAULT NULL COMMENT '批次id' COLLATE 'utf8mb4_general_ci', + `exec_idx` INT(11) NULL DEFAULT '1' COMMENT '执行序号', + `start_time` BIGINT(20) NULL DEFAULT NULL COMMENT '开始时间', + `end_time` BIGINT(20) NULL DEFAULT NULL COMMENT '结束时间', + `execute_type` VARCHAR(10) NULL DEFAULT '0' COMMENT '执行类型,0-正常执行|1-自动重试|2-手动重试' COLLATE 'utf8mb4_general_ci', + `status` VARCHAR(10) NULL DEFAULT '0' COMMENT '状态' COLLATE 'utf8mb4_general_ci', + `error_msg` TEXT(65535) NULL DEFAULT NULL COMMENT '错误信息' COLLATE 'utf8mb4_general_ci', + `video_url` VARCHAR(255) NULL DEFAULT NULL COMMENT '视频地址' COLLATE 'utf8mb4_general_ci', + `exec_result_file` VARCHAR(255) NULL DEFAULT NULL COMMENT '执行结果文件' COLLATE 'utf8mb4_general_ci', + PRIMARY KEY (`id`) USING BTREE +) +COMMENT='任务执行记录表' +COLLATE='utf8mb4_general_ci' +ENGINE=InnoDB +; +-- 2024.10.17 修改表,atu_plan_info 增加字段restry_strategy重试策略 +ALTER TABLE `atu_plan_info` + ADD COLUMN `retry_strategy` VARCHAR(10) NULL DEFAULT NULL COMMENT '重试策略 1-失败任务打包重试|2-任务失败立刻重试' COLLATE 'utf8_general_ci' AFTER `fail_retry_count`; \ No newline at end of file