[ server ] [ scheduler ]- script scheduler - 1
This commit is contained in:
@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiParam;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO;
|
||||
import io.wdd.rpc.scheduler.service.QuartzSchedulerService;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.Trigger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -26,11 +27,11 @@ public class SchedulerController {
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------
|
||||
* 页面定时任务部分
|
||||
* 脚本--页面定时脚本任务
|
||||
* 应该只有脚本功能才可以定时,目前一阶段的功能
|
||||
*/
|
||||
|
||||
@ApiOperation(value = "新增一个定时脚本任务")
|
||||
@ApiOperation(value = "[脚本]-新增一个定时脚本任务")
|
||||
@PostMapping(value = "/script/create")
|
||||
public R<HashMap<String, String>> createScriptScheduler(
|
||||
@ApiParam(name = "scheduleScript") @RequestBody() ScriptSchedulerVO scriptSchedulerVO
|
||||
@@ -42,15 +43,11 @@ public class SchedulerController {
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询所有的定时脚本任务")
|
||||
@ApiOperation(value = "[脚本]-查询所有的定时脚本任务")
|
||||
@GetMapping(value = "/script/getAll")
|
||||
public R<HashMap<String, String>> getAllScriptScheduler(
|
||||
|
||||
) {
|
||||
|
||||
|
||||
return R.ok(null);
|
||||
public R<List<JobDetail>> getAllScriptScheduler() {
|
||||
|
||||
return R.ok(octopusQuartzService.queryAllScriptScheduleMission());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ToAgentMessageSender {
|
||||
|
||||
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(
|
||||
initRabbitMQConfig.OCTOPUS_EXCHANGE,
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.time.LocalDateTime;
|
||||
@ApiModel("定时脚本任务的VO实体类")
|
||||
public class ScriptSchedulerVO {
|
||||
|
||||
public static final String SCHEDULE_MISSION_GROUP_NAME = "SCRIPT_SCHEDULER";
|
||||
public static final String SCRIPT_SCHEDULE_MISSION_GROUP_NAME = "SCRIPT_SCHEDULER";
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
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
|
||||
public class QuartzSchedulerUtils {
|
||||
@@ -30,7 +30,7 @@ public class QuartzSchedulerUtils {
|
||||
|
||||
ArrayList<LocalDateTime> time = getLastNextExecutionTime(
|
||||
scriptSchedulerDTO.getSchedulerUuid(),
|
||||
SCHEDULE_MISSION_GROUP_NAME
|
||||
SCRIPT_SCHEDULE_MISSION_GROUP_NAME
|
||||
);
|
||||
|
||||
LocalDateTime nextExecutionTime = time.get(1);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.wdd.rpc.scheduler.service;
|
||||
|
||||
import io.wdd.rpc.scheduler.beans.OctopusQuartzJob;
|
||||
import io.wdd.rpc.scheduler.beans.ScriptSchedulerVO;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.Trigger;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
@@ -83,6 +84,14 @@ public interface QuartzSchedulerService {
|
||||
*/
|
||||
List<Map<String, Object>> queryAllMission();
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有定时脚本任务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<JobDetail> queryAllScriptScheduleMission();
|
||||
|
||||
/**
|
||||
* 获取正在运行的任务job
|
||||
* @return
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
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 org.quartz.TriggerBuilder.newTrigger;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
|
||||
this.addMission(
|
||||
AgentScriptSchedulerJob.class,
|
||||
scriptSchedulerDTO.getSchedulerUuid(),
|
||||
SCHEDULE_MISSION_GROUP_NAME,
|
||||
SCRIPT_SCHEDULE_MISSION_GROUP_NAME,
|
||||
0,
|
||||
// 立即开始本次任务 1ms wait
|
||||
scriptSchedulerDTO.getCronExpress(),
|
||||
@@ -82,12 +82,18 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
|
||||
|
||||
HashMap<String, String> futureExecutionResultKey = quartzSchedulerUtils.getFutureExecutionResultKey(scriptSchedulerDTO);
|
||||
|
||||
log.info("futureExecutionResultKey is => {}", futureExecutionResultKey);
|
||||
log.info(
|
||||
"futureExecutionResultKey is => {}",
|
||||
futureExecutionResultKey
|
||||
);
|
||||
|
||||
// persistent the script scheduled mission
|
||||
// dto should store more info
|
||||
ScriptSchedulerPO scriptSchedulerPO = convertToScriptSchedulerPO(scriptSchedulerDTO);
|
||||
log.info("scriptSchedulerPO is => {}", scriptSchedulerPO);
|
||||
log.info(
|
||||
"scriptSchedulerPO is => {}",
|
||||
scriptSchedulerPO
|
||||
);
|
||||
|
||||
// scriptSchedulerService.save(scriptSchedulerPO);
|
||||
|
||||
@@ -502,6 +508,37 @@ public class QuartzSchedulerServiceImpl implements QuartzSchedulerService {
|
||||
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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user