Skip to content

Commit

Permalink
Merge pull request #3246 from jsonwan/github_fix/create_cron
Browse files Browse the repository at this point in the history
fix: 创建定时任务参数校验异常 #3245
  • Loading branch information
wangyu096 authored Oct 14, 2024
2 parents 8d5d780 + 3206e48 commit 41b9dc3
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public CronJobInfoDTO createCronJobInfo(String username, CronJobInfoDTO cronJobI
checkCronJobPlanOrScript(cronJobInfo);
saveSnapShotForHostVaiableValue(cronJobInfo);

// 有执行方案运行权限,才能用该执行方案创建定时任务
authExecuteTask(cronJobInfo);
cronJobInfo.setCreateTime(DateUtils.currentTimeSeconds());
cronJobInfo.setEnable(false);

Expand Down Expand Up @@ -253,23 +255,11 @@ public CronJobInfoDTO updateCronJobInfo(String username, CronJobInfoDTO cronJobI
processCronJobVariableValueMask(cronJobInfo);

if (cronJobInfo.getEnable()) {
try {
List<ServiceTaskVariable> taskVariables = null;
if (CollectionUtils.isNotEmpty(cronJobInfo.getVariableValue())) {
taskVariables =
cronJobInfo.getVariableValue().parallelStream()
.map(CronJobVariableDTO::toServiceTaskVariable).collect(Collectors.toList());
}
executeTaskService.authExecuteTask(cronJobInfo.getAppId(), cronJobInfo.getTaskPlanId(),
cronJobInfo.getId(), cronJobInfo.getName(), taskVariables, cronJobInfo.getLastModifyUser());
if (cronJobDAO.updateCronJobById(cronJobInfo)) {
informAllToAddJobToQuartz(cronJobInfo.getAppId(), cronJobInfo.getId());
} else {
throw new InternalException(ErrorCode.UPDATE_CRON_JOB_FAILED);
}
} catch (TaskExecuteAuthFailedException e) {
log.error("Error while pre auth cron execute!", e);
throw e;
authExecuteTask(cronJobInfo);
if (cronJobDAO.updateCronJobById(cronJobInfo)) {
informAllToAddJobToQuartz(cronJobInfo.getAppId(), cronJobInfo.getId());
} else {
throw new InternalException(ErrorCode.UPDATE_CRON_JOB_FAILED);
}
} else {
if (cronJobDAO.updateCronJobById(cronJobInfo)) {
Expand All @@ -289,6 +279,22 @@ public CronJobInfoDTO updateCronJobInfo(String username, CronJobInfoDTO cronJobI
return updateCron;
}

private void authExecuteTask(CronJobInfoDTO cronJobInfo){
try {
List<ServiceTaskVariable> taskVariables = null;
if (CollectionUtils.isNotEmpty(cronJobInfo.getVariableValue())) {
taskVariables =
cronJobInfo.getVariableValue().parallelStream()
.map(CronJobVariableDTO::toServiceTaskVariable).collect(Collectors.toList());
}
executeTaskService.authExecuteTask(cronJobInfo.getAppId(), cronJobInfo.getTaskPlanId(),
cronJobInfo.getId(), cronJobInfo.getName(), taskVariables, cronJobInfo.getLastModifyUser());
} catch (TaskExecuteAuthFailedException e) {
log.error("Error while pre auth cron execute!", e);
throw e;
}
}

/**
* 保存定时任务主机变量中的IP等快照信息
*
Expand Down

0 comments on commit 41b9dc3

Please sign in to comment.