[ server ] [ scheduler ]- script scheduler accomplish - 1

This commit is contained in:
zeaslity
2023-02-06 14:10:32 +08:00
parent d23608dec3
commit 2fb0252b15
5 changed files with 20 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ public class SchedulerController {
@ApiOperation(value = "[脚本]-删除定时脚本任务") @ApiOperation(value = "[脚本]-删除定时脚本任务")
@PostMapping(value = "/script/delete") @PostMapping(value = "/script/delete")
public R<Boolean> deleteScriptScheduler( public R<Boolean> deleteScriptScheduler(
@RequestParam(value = "scriptJobUUID") @ApiParam(value = "scriptJobUUID", name = "定时脚本任务UUID") String scriptJobUUID @RequestParam(value = "scriptJobUUID") @ApiParam(value = "定时脚本任务UUID", name = "scriptJobUUID") String scriptJobUUID
) { ) {
return R.ok(octopusQuartzService.deleteScriptScheduleMission(scriptJobUUID)); return R.ok(octopusQuartzService.deleteScriptScheduleMission(scriptJobUUID));

View File

@@ -26,7 +26,7 @@ public class QuartzSchedulerUtils {
* @param scriptSchedulerDTO dto * @param scriptSchedulerDTO dto
* @return dto中存储的 未来ExecutionKey对象 * @return dto中存储的 未来ExecutionKey对象
*/ */
public HashMap<String, String> getFutureExecutionResultKey(ScriptSchedulerDTO scriptSchedulerDTO) { public HashMap<String, String> generateAndSetFutureExecutionResultKey(ScriptSchedulerDTO scriptSchedulerDTO) {
ArrayList<LocalDateTime> time = getLastNextExecutionTime( ArrayList<LocalDateTime> time = getLastNextExecutionTime(
scriptSchedulerDTO.getSchedulerUuid(), scriptSchedulerDTO.getSchedulerUuid(),

View File

@@ -10,6 +10,8 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
import javax.annotation.Resource; import javax.annotation.Resource;
import static io.wdd.rpc.scheduler.service.QuartzSchedulerServiceImpl.SCRIPT_SCHEDULER_MISSION_KEY;
public class AgentScriptSchedulerJob extends QuartzJobBean { public class AgentScriptSchedulerJob extends QuartzJobBean {
@Resource @Resource
@@ -24,7 +26,7 @@ public class AgentScriptSchedulerJob extends QuartzJobBean {
.getJobDataMap(); .getJobDataMap();
// ScriptScheduleDTO // ScriptScheduleDTO
ScriptSchedulerDTO scriptSchedulerDTO = (ScriptSchedulerDTO) jobDataMap.get("scriptSchedulerDTO"); ScriptSchedulerDTO scriptSchedulerDTO = (ScriptSchedulerDTO) jobDataMap.get(SCRIPT_SCHEDULER_MISSION_KEY);
// 调用实际任务执行器 // 调用实际任务执行器
agentApplyScheduledScript.apply(scriptSchedulerDTO); agentApplyScheduledScript.apply(scriptSchedulerDTO);

View File

@@ -48,6 +48,10 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
@Autowired @Autowired
private Scheduler scheduler; private Scheduler scheduler;
/**
* 保存 定时脚本任务的中间DTO在Quartz框架中JobDataMap的Key名称
*/
public static final String SCRIPT_SCHEDULER_MISSION_KEY = "scriptSchedulerDTO";
/** /**
* -------------------------------------------------------------- * --------------------------------------------------------------
* 页面定时任务部分 * 页面定时任务部分
@@ -68,7 +72,7 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
// bind job and trigger // bind job and trigger
HashMap<String, Object> dataMap = new HashMap<>(); HashMap<String, Object> dataMap = new HashMap<>();
dataMap.put( dataMap.put(
"scriptSchedulerDTO", SCRIPT_SCHEDULER_MISSION_KEY,
scriptSchedulerDTO scriptSchedulerDTO
); );
this.addMission( this.addMission(
@@ -83,7 +87,7 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
dataMap dataMap
); );
HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.getFutureExecutionResultKey(scriptSchedulerDTO); HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.generateAndSetFutureExecutionResultKey(scriptSchedulerDTO);
log.info( log.info(
"futureExecutionResultKey is => {}", "futureExecutionResultKey is => {}",
@@ -602,6 +606,9 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
// 该Job存在 // 该Job存在
// 修改JobDetail信息 // 修改JobDetail信息
ScriptSchedulerDTO scriptSchedulerDTO = validateAndConvertToScriptSchedulerDTO(scriptSchedulerVO); ScriptSchedulerDTO scriptSchedulerDTO = validateAndConvertToScriptSchedulerDTO(scriptSchedulerVO);
JobDataMap map = jobDetail.getJobDataMap();
map.put(SCRIPT_SCHEDULER_MISSION_KEY,
scriptSchedulerDTO);
// 修改 Mission相应的 cron时间信息 // 修改 Mission相应的 cron时间信息
updateMission( updateMission(
@@ -610,6 +617,9 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
scriptSchedulerDTO.getCronExpress() scriptSchedulerDTO.getCronExpress()
); );
// 修改任务计划执行时间Key
quartzSchedulerUtils.generateAndSetFutureExecutionResultKey(scriptSchedulerDTO);
return jobDetail; return jobDetail;
} }
@@ -670,7 +680,8 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
return scheduler return scheduler
.getTriggerKeys( .getTriggerKeys(
GroupMatcher.groupEquals(JOB_GROUP_NAME) // GroupMatcher.groupEquals(JOB_GROUP_NAME)
GroupMatcher.anyGroup()
) )
.stream() .stream()
.map( .map(

View File

@@ -42,7 +42,7 @@ public class AgentApplyScheduledScript {
scriptSchedulerDTO.setResultKeyList(resultKeyList); scriptSchedulerDTO.setResultKeyList(resultKeyList);
// 更新DTO中的下次执行时间 否则会出错 // 更新DTO中的下次执行时间 否则会出错
HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.getFutureExecutionResultKey(scriptSchedulerDTO); HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.generateAndSetFutureExecutionResultKey(scriptSchedulerDTO);
log.info( log.info(
"futureExecutionResultKey in scheduled work is => {}", "futureExecutionResultKey in scheduled work is => {}",