use of com.dtstack.taier.scheduler.dto.schedule.SavaTaskDTO in project Taier by DTStack.
the class BatchTaskService method publishBatchTaskInfo.
/**
* 批量发布任务至engine
* @param publishTask 要发布的task集合
* @param tenantId 项目id
* @param userId 用户id
* @param publishDesc 发布描述
* @param isRoot 是否是管理员
* @param ignoreCheck 忽略检查
* @return 发布结果
*/
public TaskCheckResultVO publishBatchTaskInfo(BatchTask publishTask, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
// 判断任务责任人是否存在 如果任务责任人不存在或无权限 不允许提交
User user = userService.getById(publishTask.getCreateUserId());
if (user == null) {
throw new RdosDefineException(String.format("%s任务责任人在数栈中不存在", publishTask.getName()));
}
TaskCheckResultVO checkResultVO = new TaskCheckResultVO();
checkResultVO.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
// 检查任务是否可以发布并记录版本信息
TaskCheckResultVO resultVO = checkTaskAndSaveVersion(publishTask, tenantId, userId, publishDesc, isRoot, ignoreCheck);
if (!PublishTaskStatusEnum.NOMAL.getType().equals(resultVO.getErrorSign())) {
// 做一下优化 如果是工作流任务的话 把任务名称打印出来
if (publishTask.getFlowId() > 0) {
resultVO.setErrorMessage(String.format("任务:%s提交失败,原因是:%s", publishTask.getName(), resultVO.getErrorMessage()));
}
return resultVO;
}
// 发布任务中所有的依赖关系
List<Long> parentTaskIds = Lists.newArrayList();
ScheduleTaskShadeDTO scheduleTaskShadeDTO = buildScheduleTaskShadeDTO(publishTask, parentTaskIds);
// 提交任务参数信息并保存任务记录和更新任务状态
try {
BatchTask batchTask = getOneWithError(scheduleTaskShadeDTO.getTaskId());
String extraInfo = this.batchJobService.getExtraInfo(batchTask, userId, null);
scheduleTaskShadeDTO.setExtraInfo(extraInfo);
// 无异常保存一条任务记录并更新任务状态
saveRecordAndUpdateSubmitStatus(batchTask, tenantId, userId, TaskOperateType.COMMIT.getType(), ESubmitStatus.SUBMIT.getStatus());
} catch (Exception e) {
LOGGER.error("send task error {} ", scheduleTaskShadeDTO.getTaskId(), e);
throw new RdosDefineException(String.format("任务提交异常:%s", e.getMessage()), e);
}
SavaTaskDTO savaTaskDTO = new SavaTaskDTO();
savaTaskDTO.setScheduleTaskShadeDTO(scheduleTaskShadeDTO);
savaTaskDTO.setParentTaskIdList(parentTaskIds);
// 批量发布任务
this.taskService.saveTask(savaTaskDTO);
LOGGER.info("待发布任务参数提交完毕");
return checkResultVO;
}
Aggregations