[ server ] [ scheduler ]- script scheduler - 1

This commit is contained in:
zeaslity
2023-02-03 17:07:15 +08:00
parent 87b1b2398b
commit 5994b06c2a
6 changed files with 60 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiParam;
import io.wdd.common.beans.response.R; import io.wdd.common.beans.response.R;
import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO; import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO;
import io.wdd.rpc.scheduler.service.QuartzSchedulerService; import io.wdd.rpc.scheduler.service.QuartzSchedulerService;
import org.quartz.JobDetail;
import org.quartz.Trigger; import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -26,11 +27,11 @@ public class SchedulerController {
/** /**
* -------------------------------------------------------------- * --------------------------------------------------------------
* 页面定时任务部分 * 脚本--页面定时脚本任务
* 应该只有脚本功能才可以定时,目前一阶段的功能 * 应该只有脚本功能才可以定时,目前一阶段的功能
*/ */
@ApiOperation(value = "新增一个定时脚本任务") @ApiOperation(value = "[脚本]-新增一个定时脚本任务")
@PostMapping(value = "/script/create") @PostMapping(value = "/script/create")
public R<HashMap<String, String>> createScriptScheduler( public R<HashMap<String, String>> createScriptScheduler(
@ApiParam(name = "scheduleScript") @RequestBody() ScriptSchedulerVO scriptSchedulerVO @ApiParam(name = "scheduleScript") @RequestBody() ScriptSchedulerVO scriptSchedulerVO
@@ -42,15 +43,11 @@ public class SchedulerController {
} }
@ApiOperation(value = "查询所有的定时脚本任务") @ApiOperation(value = "[脚本]-查询所有的定时脚本任务")
@GetMapping(value = "/script/getAll") @GetMapping(value = "/script/getAll")
public R<HashMap<String, String>> getAllScriptScheduler( public R<List<JobDetail>> getAllScriptScheduler() {
) {
return R.ok(null);
return R.ok(octopusQuartzService.queryAllScriptScheduleMission());
} }
/** /**

View File

@@ -53,7 +53,7 @@ public class ToAgentMessageSender {
public void send(OctopusMessage octopusMessage) { public void send(OctopusMessage octopusMessage) {
log.info("OctopusMessage {} send to agent {}", octopusMessage, octopusMessage.getUuid()); log.debug("OctopusMessage {} send to agent {}", octopusMessage, octopusMessage.getUuid());
rabbitTemplate.convertAndSend( rabbitTemplate.convertAndSend(
initRabbitMQConfig.OCTOPUS_EXCHANGE, initRabbitMQConfig.OCTOPUS_EXCHANGE,

View File

@@ -19,7 +19,7 @@ import java.time.LocalDateTime;
@ApiModel("定时脚本任务的VO实体类") @ApiModel("定时脚本任务的VO实体类")
public class ScriptSchedulerVO { public class ScriptSchedulerVO {
public static final String SCHEDULE_MISSION_GROUP_NAME = "SCRIPT_SCHEDULER"; public static final String SCRIPT_SCHEDULE_MISSION_GROUP_NAME = "SCRIPT_SCHEDULER";
/** /**
* *

View File

@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import static io.wdd.rpc.scheduler.beans.ScriptSchedulerVO.SCHEDULE_MISSION_GROUP_NAME; import static io.wdd.rpc.scheduler.beans.ScriptSchedulerVO.SCRIPT_SCHEDULE_MISSION_GROUP_NAME;
@Component @Component
public class QuartzSchedulerUtils { public class QuartzSchedulerUtils {
@@ -30,7 +30,7 @@ public class QuartzSchedulerUtils {
ArrayList<LocalDateTime> time = getLastNextExecutionTime( ArrayList<LocalDateTime> time = getLastNextExecutionTime(
scriptSchedulerDTO.getSchedulerUuid(), scriptSchedulerDTO.getSchedulerUuid(),
SCHEDULE_MISSION_GROUP_NAME SCRIPT_SCHEDULE_MISSION_GROUP_NAME
); );
LocalDateTime nextExecutionTime = time.get(1); LocalDateTime nextExecutionTime = time.get(1);

View File

@@ -2,6 +2,7 @@ package io.wdd.rpc.scheduler.service;
import io.wdd.rpc.scheduler.beans.OctopusQuartzJob; import io.wdd.rpc.scheduler.beans.OctopusQuartzJob;
import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO; import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO;
import org.quartz.JobDetail;
import org.quartz.Trigger; import org.quartz.Trigger;
import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.scheduling.quartz.QuartzJobBean;
@@ -83,6 +84,14 @@ public interface QuartzSchedulerService {
*/ */
List<Map<String, Object>> queryAllMission(); List<Map<String, Object>> queryAllMission();
/**
* 查询所有定时脚本任务
*
* @return
*/
List<JobDetail> queryAllScriptScheduleMission();
/** /**
* 获取正在运行的任务job * 获取正在运行的任务job
* @return * @return

View File

@@ -26,7 +26,7 @@ import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static io.wdd.rpc.scheduler.beans.ScriptSchedulerVO.SCHEDULE_MISSION_GROUP_NAME; import static io.wdd.rpc.scheduler.beans.ScriptSchedulerVO.SCRIPT_SCHEDULE_MISSION_GROUP_NAME;
import static io.wdd.rpc.scheduler.service.BuildStatusScheduleTask.JOB_GROUP_NAME; import static io.wdd.rpc.scheduler.service.BuildStatusScheduleTask.JOB_GROUP_NAME;
import static org.quartz.TriggerBuilder.newTrigger; import static org.quartz.TriggerBuilder.newTrigger;
@@ -73,7 +73,7 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
this.addMission( this.addMission(
AgentScriptSchedulerJob.class, AgentScriptSchedulerJob.class,
scriptSchedulerDTO.getSchedulerUuid(), scriptSchedulerDTO.getSchedulerUuid(),
SCHEDULE_MISSION_GROUP_NAME, SCRIPT_SCHEDULE_MISSION_GROUP_NAME,
0, 0,
// 立即开始本次任务 1ms wait // 立即开始本次任务 1ms wait
scriptSchedulerDTO.getCronExpress(), scriptSchedulerDTO.getCronExpress(),
@@ -82,12 +82,18 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.getFutureExecutionResultKey(scriptSchedulerDTO); HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.getFutureExecutionResultKey(scriptSchedulerDTO);
log.info("futureExecutionResultKey is => {}", futureExecutionResultKey); log.info(
"futureExecutionResultKey is => {}",
futureExecutionResultKey
);
// persistent the script scheduled mission // persistent the script scheduled mission
// dto should store more info // dto should store more info
ScriptSchedulerPO scriptSchedulerPO = convertToScriptSchedulerPO(scriptSchedulerDTO); ScriptSchedulerPO scriptSchedulerPO = convertToScriptSchedulerPO(scriptSchedulerDTO);
log.info("scriptSchedulerPO is => {}", scriptSchedulerPO); log.info(
"scriptSchedulerPO is => {}",
scriptSchedulerPO
);
// scriptSchedulerService.save(scriptSchedulerPO); // scriptSchedulerService.save(scriptSchedulerPO);
@@ -502,6 +508,37 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
return jobList; return jobList;
} }
@Override
public List<JobDetail> queryAllScriptScheduleMission() {
try {
GroupMatcher<JobKey> matcher = GroupMatcher
.groupEquals(SCRIPT_SCHEDULE_MISSION_GROUP_NAME);
return scheduler
.getJobKeys(
matcher
)
.stream()
.map(
jobKey -> {
try {
return scheduler.getJobDetail(jobKey);
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
)
.collect(Collectors.toList());
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
/** /**
* 获取所有正在运行的job * 获取所有正在运行的job
* *