Commit 22fee9ca authored by 技术总监-万宁's avatar 技术总监-万宁

增加修改任务启动时间接口

parent 52b0c49a
......@@ -3160,7 +3160,8 @@ public enum ResponseCode {
//**scheduler-service 状态码:54000-54299***
//************************************************
SS_TASK_CREATE_FAILED(54000, "定时任务创建失败"),
SS_TASK_DELETE_FAILED(54001, "定时任务删除失败")
SS_TASK_DELETE_FAILED(54001, "定时任务删除失败"),
SS_TASK_DOES_NOT_EXIST(54002, "定时任务不存在或已执行完毕")
......
......@@ -3,11 +3,9 @@ package com.ssy.lingxi.scheduler.api.fallback;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.scheduler.api.feign.ScheduleTaskFeign;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskDefinitionVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskIdVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskQueryVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskVO;
import com.ssy.lingxi.scheduler.api.model.*;
import javax.validation.Valid;
import java.util.List;
/**
......@@ -40,6 +38,17 @@ public class ScheduleTaskFallback implements ScheduleTaskFeign {
}
/**
* 修改任务的启动时间
*
* @param updateVO 接口参数
* @return 修改结果
*/
@Override
public Wrapper<Void> updateScheduleTaskExecTime(@Valid ScheduleTaskUpdateExecTimeVO updateVO) {
return Wrapper.fail(ResponseCode.SERVICE_SCHEDULER_ERROR);
}
/**
* 调用方执行完成定时任务后,通知定时任务服务删除任务
*
* @param idVO 接口参数
......
package com.ssy.lingxi.scheduler.api.feign;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskDefinitionVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskIdVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskQueryVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskVO;
import com.ssy.lingxi.scheduler.api.model.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -39,6 +36,14 @@ public interface ScheduleTaskFeign {
Wrapper<List<ScheduleTaskDefinitionVO>> listScheduleTask(@RequestBody @Valid ScheduleTaskQueryVO queryVO);
/**
* 修改任务的启动时间
* @param updateVO 接口参数
* @return 修改结果
*/
@RequestMapping(value = "/schedule/task/time/update", method = RequestMethod.POST)
Wrapper<Void> updateScheduleTaskExecTime(@RequestBody @Valid ScheduleTaskUpdateExecTimeVO updateVO);
/**
* 删除任务
* @param idVO 接口参数
* @return 通知结果
......
package com.ssy.lingxi.scheduler.api.model;
import com.ssy.lingxi.scheduler.api.handler.annotation.TimestampAnnotation;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.io.Serializable;
/**
* 修改任务启动时间接口参数
* @author 万宁
* @version 2.0.0
* @date 2021-07-14
*/
public class ScheduleTaskUpdateExecTimeVO implements Serializable {
private static final long serialVersionUID = -4975993025367994877L;
/**
* 定时任务Id
*/
@NotNull(message = "定时任务Id要大于0")
@Positive(message = "定时任务Id要大于0")
private Long taskId;
/**
* 任务开始执行的时间,(Unix时间戳格式,精确到毫秒)
*/
@TimestampAnnotation
private Long execTime;
public Long getTaskId() {
return taskId;
}
public void setTaskId(Long taskId) {
this.taskId = taskId;
}
public Long getExecTime() {
return execTime;
}
public void setExecTime(Long execTime) {
this.execTime = execTime;
}
}
package com.ssy.lingxi.scheduler.controller;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskDefinitionVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskIdVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskQueryVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskVO;
import com.ssy.lingxi.scheduler.api.model.*;
import com.ssy.lingxi.scheduler.service.IScheduleTaskService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -49,6 +46,16 @@ public class ScheduleTaskController {
}
/**
* 修改任务的启动时间
* @param updateVO 接口参数
* @return 修改结果
*/
@RequestMapping(value = "/time/update", method = RequestMethod.POST)
public Wrapper<Void> updateScheduleTaskExecTime(@RequestBody @Valid ScheduleTaskUpdateExecTimeVO updateVO) {
return scheduleTaskService.updateScheduleTaskExecTime(updateVO);
}
/**
* 调用方执行完成定时任务后,通知定时任务模块删除任务
* @param idVO 接口参数
* @return 通知结果
......
package com.ssy.lingxi.scheduler.service;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskDefinitionVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskIdVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskQueryVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskVO;
import com.ssy.lingxi.scheduler.api.model.*;
import org.quartz.JobDetail;
import org.quartz.Trigger;
......@@ -33,6 +30,13 @@ public interface IScheduleTaskService {
Wrapper<List<ScheduleTaskDefinitionVO>> listScheduleTask(ScheduleTaskQueryVO queryVO);
/**
* 修改任务的启动时间
* @param updateVO 接口参数
* @return 修改结果
*/
Wrapper<Void> updateScheduleTaskExecTime(ScheduleTaskUpdateExecTimeVO updateVO);
/**
* 调用方执行完成定时任务后,通知定时任务模块
* @param idVO 接口参数
* @return 通知结果
......
......@@ -3,10 +3,7 @@ package com.ssy.lingxi.scheduler.serviceimpl;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskDefinitionVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskIdVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskQueryVO;
import com.ssy.lingxi.scheduler.api.model.ScheduleTaskVO;
import com.ssy.lingxi.scheduler.api.model.*;
import com.ssy.lingxi.scheduler.entity.ScheduleTaskDefinition;
import com.ssy.lingxi.scheduler.listener.ScheduleJob;
import com.ssy.lingxi.scheduler.model.ServiceConstants;
......@@ -154,6 +151,39 @@ public class ScheduleTaskServiceImpl implements IScheduleTaskService {
}
/**
* 修改任务的启动时间
*
* @param updateVO 接口参数
* @return 修改结果
*/
@Override
public Wrapper<Void> updateScheduleTaskExecTime(ScheduleTaskUpdateExecTimeVO updateVO) {
ScheduleTaskDefinition taskDefinition = taskDefinitionRepository.findById(updateVO.getTaskId()).orElse(null);
if(taskDefinition == null) {
return Wrapper.fail(ResponseCode.SS_TASK_DOES_NOT_EXIST);
}
taskDefinition.setExecTime(updateVO.getExecTime());
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(taskDefinition.getTaskName(), taskDefinition.getTaskGroup())
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMinutes(ServiceConstants.TASK_INTERVAL_MINUTES)
.withRepeatCount(ServiceConstants.TASK_REPEAT_TIMES))
.startAt(new Date(updateVO.getExecTime()))
.build();
TriggerKey triggerKey = TriggerKey.triggerKey(taskDefinition.getTaskName(), taskDefinition.getTaskGroup());
try {
scheduler.rescheduleJob(triggerKey, trigger);
} catch (Exception e) {
return Wrapper.fail(ResponseCode.SERVICE_ERROR, e.getMessage());
}
taskDefinitionRepository.saveAndFlush(taskDefinition);
return Wrapper.success();
}
/**
* 调用方执行完成定时任务后,通知定时任务模块
*
* @param idVO 接口参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment