feat:(1.2.0-beta2): 优化openapi
This commit is contained in:
parent
a170b03898
commit
a1e1091eb3
@ -29,11 +29,6 @@ public class JobResponseVO {
|
||||
*/
|
||||
private String argsStr;
|
||||
|
||||
/**
|
||||
* 参数类型 text/json
|
||||
*/
|
||||
private String argsType;
|
||||
|
||||
/**
|
||||
* 扩展字段
|
||||
*/
|
||||
@ -104,11 +99,6 @@ public class JobResponseVO {
|
||||
*/
|
||||
private Integer parallelNum;
|
||||
|
||||
/**
|
||||
* bucket
|
||||
*/
|
||||
private Integer bucketIndex;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@ -124,9 +114,4 @@ public class JobResponseVO {
|
||||
*/
|
||||
private LocalDateTime updateDt;
|
||||
|
||||
/**
|
||||
* 逻辑删除 1、删除
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.aizuda.snailjob.client.job.core.dto;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.handler.add.Add;
|
||||
import com.aizuda.snailjob.client.job.core.handler.update.Update;
|
||||
import com.aizuda.snailjob.client.job.core.handler.update.UpdateHandler;
|
||||
import com.aizuda.snailjob.common.core.enums.ExecutorTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
@ -8,18 +11,22 @@ import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RequestAddJobDTO{
|
||||
public class RequestAddOrUpdateJobDTO {
|
||||
|
||||
@NotNull(message = "id 不能为空", groups = Update.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotBlank(message = "jobName 不能为空")
|
||||
@NotBlank(message = "jobName 不能为空", groups = Add.class)
|
||||
private String jobName;
|
||||
|
||||
/**
|
||||
* 重试状态 0、关闭、1、开启
|
||||
* {@link StatusEnum}
|
||||
*/
|
||||
@NotNull(message = "jobStatus 不能为空")
|
||||
@NotNull(message = "jobStatus 不能为空", groups = Add.class)
|
||||
private Integer jobStatus;
|
||||
|
||||
/**
|
||||
@ -35,69 +42,69 @@ public class RequestAddJobDTO{
|
||||
/**
|
||||
* 执行器路由策略
|
||||
*/
|
||||
@NotNull(message = "routeKey 不能为空")
|
||||
@NotNull(message = "routeKey 不能为空", groups = Add.class)
|
||||
private Integer routeKey;
|
||||
|
||||
/**
|
||||
* 执行器类型
|
||||
* {@link ExecutorTypeEnum}
|
||||
*/
|
||||
@NotNull(message = "executorType 不能为空")
|
||||
@NotNull(message = "executorType 不能为空", groups = Add.class)
|
||||
private Integer executorType;
|
||||
|
||||
/**
|
||||
* 执行器名称
|
||||
*/
|
||||
@NotBlank(message = "executorInfo 不能为空")
|
||||
@NotBlank(message = "executorInfo 不能为空", groups = Add.class)
|
||||
private String executorInfo;
|
||||
|
||||
/**
|
||||
* 触发类型 2. 固定时间 3.CRON 表达式 99.工作流
|
||||
*/
|
||||
@NotNull(message = "triggerType 不能为空")
|
||||
@NotNull(message = "triggerType 不能为空", groups = Add.class)
|
||||
private Integer triggerType;
|
||||
|
||||
/**
|
||||
* 间隔时长
|
||||
*/
|
||||
@NotNull(message = "triggerInterval 不能为空")
|
||||
@NotNull(message = "triggerInterval 不能为空", groups = Add.class)
|
||||
private String triggerInterval;
|
||||
|
||||
/**
|
||||
* 阻塞策略 1、丢弃 2、覆盖 3、并行
|
||||
*/
|
||||
@NotNull(message = "blockStrategy 不能为空")
|
||||
@NotNull(message = "blockStrategy 不能为空", groups = Add.class)
|
||||
private Integer blockStrategy;
|
||||
|
||||
/**
|
||||
* 任务执行超时时间,单位秒
|
||||
*/
|
||||
@NotNull(message = "executorTimeout 不能为空")
|
||||
@NotNull(message = "executorTimeout 不能为空", groups = Add.class)
|
||||
private Integer executorTimeout;
|
||||
|
||||
/**
|
||||
* 最大重试次数
|
||||
*/
|
||||
@NotNull(message = "maxRetryTimes 不能为空")
|
||||
@NotNull(message = "maxRetryTimes 不能为空", groups = Add.class)
|
||||
private Integer maxRetryTimes;
|
||||
|
||||
/**
|
||||
* 重试间隔(s)
|
||||
*/
|
||||
@NotNull(message = "retryInterval 不能为空")
|
||||
@NotNull(message = "retryInterval 不能为空", groups = Add.class)
|
||||
private Integer retryInterval;
|
||||
|
||||
/**
|
||||
* 任务类型
|
||||
* {@link JobTaskTypeEnum}
|
||||
*/
|
||||
@NotNull(message = "taskType 不能为空")
|
||||
@NotNull(message = "taskType 不能为空", groups = Add.class)
|
||||
private Integer taskType;
|
||||
|
||||
/**
|
||||
* 并行数
|
||||
*/
|
||||
@NotNull(message = "parallelNum 不能为空")
|
||||
@NotNull(message = "parallelNum 不能为空", groups = Add.class)
|
||||
private Integer parallelNum;
|
||||
|
||||
/**
|
@ -1,102 +0,0 @@
|
||||
package com.aizuda.snailjob.client.job.core.dto;
|
||||
|
||||
import com.aizuda.snailjob.common.core.enums.ExecutorTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2023-10-11 22:37:55
|
||||
* @since 2.4.0
|
||||
*/
|
||||
@Data
|
||||
public class RequestUpdateJobDTO {
|
||||
@NotNull(message = "id 不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String jobName;
|
||||
|
||||
/**
|
||||
* 重试状态 0、关闭、1、开启
|
||||
* {@link StatusEnum}
|
||||
*/
|
||||
private Integer jobStatus;
|
||||
|
||||
/**
|
||||
* 执行方法参数
|
||||
*/
|
||||
private String argsStr;
|
||||
|
||||
/**
|
||||
* 参数类型 text/json
|
||||
*/
|
||||
private Integer argsType;
|
||||
|
||||
/**
|
||||
* 执行器路由策略
|
||||
*/
|
||||
private Integer routeKey;
|
||||
|
||||
/**
|
||||
* 执行器类型
|
||||
* {@link ExecutorTypeEnum}
|
||||
*/
|
||||
private Integer executorType;
|
||||
|
||||
/**
|
||||
* 执行器名称
|
||||
*/
|
||||
private String executorInfo;
|
||||
|
||||
/**
|
||||
* 触发类型 2. 固定时间 3.CRON 表达式 99.工作流
|
||||
*/
|
||||
private Integer triggerType;
|
||||
|
||||
/**
|
||||
* 间隔时长
|
||||
*/
|
||||
private String triggerInterval;
|
||||
|
||||
/**
|
||||
* 阻塞策略 1、丢弃 2、覆盖 3、并行
|
||||
*/
|
||||
private Integer blockStrategy;
|
||||
|
||||
/**
|
||||
* 任务执行超时时间,单位秒
|
||||
*/
|
||||
private Integer executorTimeout;
|
||||
|
||||
/**
|
||||
* 最大重试次数
|
||||
*/
|
||||
private Integer maxRetryTimes;
|
||||
|
||||
/**
|
||||
* 重试间隔(s)
|
||||
*/
|
||||
private Integer retryInterval;
|
||||
|
||||
/**
|
||||
* 任务类型
|
||||
* {@link JobTaskTypeEnum}
|
||||
*/
|
||||
private Integer taskType;
|
||||
|
||||
/**
|
||||
* 并行数
|
||||
*/
|
||||
private Integer parallelNum;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.aizuda.snailjob.client.job.core.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum JobTypeEnum {
|
||||
JOB(1),
|
||||
WORKFLOW(2);
|
||||
|
||||
private final int type;
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestAddOrUpdateJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.*;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum.*;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-10-19 22:34:38
|
||||
* @since sj_1.2.0
|
||||
*/
|
||||
public abstract class AbstractParamsHandler<H, R> extends AbstractRequestHandler<R> {
|
||||
protected static final String SHARD_NUM = "shardNum";
|
||||
@Getter
|
||||
private final RequestAddOrUpdateJobDTO reqDTO;
|
||||
@Setter
|
||||
private H r;
|
||||
|
||||
public AbstractParamsHandler(JobTaskTypeEnum taskType) {
|
||||
this.reqDTO = new RequestAddOrUpdateJobDTO();
|
||||
// 默认创建就开启
|
||||
reqDTO.setJobStatus(StatusEnum.YES.getStatus());
|
||||
// 设置任务类型
|
||||
reqDTO.setTaskType(taskType.getType());
|
||||
// 默认java
|
||||
reqDTO.setExecutorType(ExecutorTypeEnum.JAVA.getType());
|
||||
}
|
||||
|
||||
protected H setId(Long id) {
|
||||
reqDTO.setId(id);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改时会直接覆盖之前的任务参数
|
||||
* 修改参数
|
||||
*
|
||||
* @param argsStr
|
||||
* @return
|
||||
*/
|
||||
private H setArgsStr(Map<String, Object> argsStr) {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(reqDTO.getArgsStr())) {
|
||||
args = JsonUtil.parseHashMap(reqDTO.getArgsStr());
|
||||
}
|
||||
args.putAll(argsStr);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(args));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.JSON.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改Reduce的分片数
|
||||
* 只允许MAP_REDUCE设置
|
||||
*
|
||||
* @param shardNum
|
||||
* @return
|
||||
*/
|
||||
protected H setShardNum(Integer shardNum) {
|
||||
// 设置分片
|
||||
if (shardNum != null) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
map.put(SHARD_NUM, shardNum);
|
||||
setArgsStr(map);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务名
|
||||
*
|
||||
* @param jobName 任务名
|
||||
* @return
|
||||
*/
|
||||
public H setJobName(String jobName) {
|
||||
reqDTO.setJobName(jobName);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加参数,可支持多次添加
|
||||
* 静态分片不可使用该方法
|
||||
*
|
||||
* @param argsKey 参数名
|
||||
* @param argsValue 参数值
|
||||
* @return
|
||||
*/
|
||||
protected H addArgsStr(String argsKey, Object argsValue) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(reqDTO.getArgsStr())) {
|
||||
map = JsonUtil.parseHashMap(reqDTO.getArgsStr());
|
||||
}
|
||||
map.put(argsKey, argsValue);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(map));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.JSON.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加静态分片相关参数
|
||||
*
|
||||
* @param shardingValue 分片参数
|
||||
* @return r
|
||||
*/
|
||||
protected H addShardingArgs(String... shardingValue) {
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(shardingValue));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.TEXT.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置路由
|
||||
*
|
||||
* @param algorithmEnum 路由算法
|
||||
* @return r
|
||||
*/
|
||||
protected H setRouteKey(AllocationAlgorithmEnum algorithmEnum) {
|
||||
reqDTO.setRouteKey(algorithmEnum.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置执行器信息
|
||||
*
|
||||
* @param executorInfo 执行器信息
|
||||
* @return r
|
||||
*/
|
||||
public H setExecutorInfo(String executorInfo) {
|
||||
reqDTO.setExecutorInfo(executorInfo);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置调度类型
|
||||
*
|
||||
* @param triggerType 触发类型
|
||||
* @return r
|
||||
*/
|
||||
public H setTriggerType(TriggerTypeEnum triggerType) {
|
||||
reqDTO.setTriggerType(triggerType.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触发间隔;
|
||||
* 单位:秒
|
||||
* 注意: 此方法必须满足【triggerType==SCHEDULED_TIME】
|
||||
*
|
||||
* @param triggerInterval 触发间隔
|
||||
* @return r
|
||||
*/
|
||||
public H setTriggerInterval(Integer triggerInterval) {
|
||||
Assert.isTrue(reqDTO.getTriggerType() == SCHEDULED_TIME.getType(),
|
||||
() -> new SnailJobClientException("此方法只限制固定时间使用"));
|
||||
setTriggerInterval(String.valueOf(triggerInterval));
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触发间隔;
|
||||
* 单位:秒
|
||||
* 工作流无需配置
|
||||
*
|
||||
* @param triggerInterval 触发间隔
|
||||
* @return r
|
||||
*/
|
||||
public H setTriggerInterval(String triggerInterval) {
|
||||
// 若是工作流则没有调度时间
|
||||
Assert.isFalse(reqDTO.getTriggerType() == WORK_FLOW.getType(),
|
||||
() -> new SnailJobClientException("工作流无需配置"));
|
||||
reqDTO.setTriggerInterval(triggerInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置阻塞策略
|
||||
*
|
||||
* @param blockStrategy 阻塞策略
|
||||
* @return r
|
||||
*/
|
||||
public H setBlockStrategy(BlockStrategyEnum blockStrategy) {
|
||||
reqDTO.setBlockStrategy(blockStrategy.getBlockStrategy());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置执行器超时时间
|
||||
*
|
||||
* @param executorTimeout 超时时间(单位:秒)
|
||||
* @return r
|
||||
*/
|
||||
public H setExecutorTimeout(Integer executorTimeout) {
|
||||
reqDTO.setExecutorTimeout(executorTimeout);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务最大重试次数
|
||||
*
|
||||
* @param maxRetryTimes 最大超时时间
|
||||
* @return r
|
||||
*/
|
||||
public H setMaxRetryTimes(Integer maxRetryTimes) {
|
||||
reqDTO.setMaxRetryTimes(maxRetryTimes);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置重试间隔
|
||||
*
|
||||
* @param retryInterval 重试间隔
|
||||
* @return r
|
||||
*/
|
||||
public H setRetryInterval(Integer retryInterval) {
|
||||
reqDTO.setRetryInterval(retryInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置并发数量
|
||||
*
|
||||
* @param parallelNum 并发数量
|
||||
* @return r
|
||||
*/
|
||||
protected H setParallelNum(Integer parallelNum) {
|
||||
reqDTO.setParallelNum(parallelNum);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置定时任务描述
|
||||
*
|
||||
* @param description 任务描述
|
||||
* @return r
|
||||
*/
|
||||
public H setDescription(String description) {
|
||||
reqDTO.setDescription(description);
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.add;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-10-20 11:59:02
|
||||
* @since sj_1.2.0
|
||||
*/
|
||||
public interface Add {
|
||||
}
|
@ -2,220 +2,47 @@ package com.aizuda.snailjob.client.job.core.handler.add;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestAddJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractParamsHandler;
|
||||
import com.aizuda.snailjob.client.job.core.util.ValidatorUtils;
|
||||
import com.aizuda.snailjob.common.core.enums.*;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum.WORK_FLOW;
|
||||
|
||||
public abstract class AddHandler<R> extends AbstractRequestHandler<Long> {
|
||||
private final RequestAddJobDTO reqDTO;
|
||||
@Setter
|
||||
private R r;
|
||||
public AddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
this.reqDTO = new RequestAddJobDTO();
|
||||
// 默认创建就开启
|
||||
reqDTO.setJobStatus(StatusEnum.YES.getStatus());
|
||||
// 设置任务类型
|
||||
reqDTO.setTaskType(taskType.getType());
|
||||
// 默认java
|
||||
reqDTO.setExecutorType(ExecutorTypeEnum.JAVA.getType());
|
||||
// 设置分片
|
||||
if (shardNum != null) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
map.put(SHARD_NUM, shardNum);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(map));
|
||||
}
|
||||
public abstract class AddHandler<H> extends AbstractParamsHandler<H, Long> {
|
||||
|
||||
public AddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long doExecute() {
|
||||
String data = JsonUtil.toJsonString(client.addJob(reqDTO).getData());
|
||||
Result<Object> result = client.addJob(getReqDTO());
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
String data = JsonUtil.toJsonString(result.getData());
|
||||
return Long.valueOf(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeExecute() {
|
||||
// 此次是兜底覆盖,工作流是没有调度时间
|
||||
if (reqDTO.getTriggerType() == WORK_FLOW.getType()) {
|
||||
if (getReqDTO().getTriggerType() == WORK_FLOW.getType()) {
|
||||
setTriggerInterval("*");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterExecute(Long aLong) {
|
||||
protected void afterExecute(Long id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Boolean, String> checkRequest() {
|
||||
return ValidatorUtils.validateEntity(reqDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务名
|
||||
*
|
||||
* @param jobName 任务名
|
||||
* @return
|
||||
*/
|
||||
public R setJobName(String jobName) {
|
||||
reqDTO.setJobName(jobName);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加参数,可支持多次添加
|
||||
* 静态分片不可使用该方法
|
||||
*
|
||||
* @param argsKey 参数名
|
||||
* @param argsValue 参数值
|
||||
* @return
|
||||
*/
|
||||
protected R addArgsStr(String argsKey, Object argsValue) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(reqDTO.getArgsStr())) {
|
||||
map = JsonUtil.parseHashMap(reqDTO.getArgsStr());
|
||||
}
|
||||
map.put(argsKey, argsValue);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(map));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.JSON.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加静态分片相关参数
|
||||
*
|
||||
* @param shardingValue 分片参数
|
||||
* @return r
|
||||
*/
|
||||
protected R addShardingArgs(String ...shardingValue) {
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(shardingValue));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.TEXT.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置路由
|
||||
*
|
||||
* @param algorithmEnum 路由算法
|
||||
* @return r
|
||||
*/
|
||||
protected R setRouteKey(AllocationAlgorithmEnum algorithmEnum) {
|
||||
reqDTO.setRouteKey(algorithmEnum.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置执行器信息
|
||||
*
|
||||
* @param executorInfo 执行器信息
|
||||
* @return r
|
||||
*/
|
||||
public R setExecutorInfo(String executorInfo) {
|
||||
reqDTO.setExecutorInfo(executorInfo);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置调度类型
|
||||
*
|
||||
* @param triggerType 触发类型
|
||||
* @return r
|
||||
*/
|
||||
public R setTriggerType(TriggerTypeEnum triggerType) {
|
||||
reqDTO.setTriggerType(triggerType.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触发间隔;
|
||||
* 单位:秒
|
||||
* 工作流无需配置
|
||||
*
|
||||
* @param triggerInterval 触发间隔
|
||||
* @return r
|
||||
*/
|
||||
public R setTriggerInterval(String triggerInterval) {
|
||||
// 若是工作流则没有调度时间
|
||||
Assert.isTrue(reqDTO.getTriggerType() == WORK_FLOW.getType(),
|
||||
() -> new SnailJobClientException("工作流无需配置"));
|
||||
reqDTO.setTriggerInterval(triggerInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置阻塞策略
|
||||
*
|
||||
* @param blockStrategy 阻塞策略
|
||||
* @return r
|
||||
*/
|
||||
public R setBlockStrategy(BlockStrategyEnum blockStrategy) {
|
||||
reqDTO.setBlockStrategy(blockStrategy.getBlockStrategy());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置执行器超时时间
|
||||
*
|
||||
* @param executorTimeout 超时时间(单位:秒)
|
||||
* @return r
|
||||
*/
|
||||
public R setExecutorTimeout(Integer executorTimeout) {
|
||||
reqDTO.setExecutorTimeout(executorTimeout);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务最大重试次数
|
||||
*
|
||||
* @param maxRetryTimes 最大超时时间
|
||||
* @return r
|
||||
*/
|
||||
public R setMaxRetryTimes(Integer maxRetryTimes) {
|
||||
reqDTO.setMaxRetryTimes(maxRetryTimes);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置重试间隔
|
||||
*
|
||||
* @param retryInterval 重试间隔
|
||||
* @return r
|
||||
*/
|
||||
public R setRetryInterval(Integer retryInterval) {
|
||||
reqDTO.setRetryInterval(retryInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置并发数量
|
||||
*
|
||||
* @param parallelNum 并发数量
|
||||
* @return r
|
||||
*/
|
||||
protected R setParallelNum(Integer parallelNum) {
|
||||
reqDTO.setParallelNum(parallelNum);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置定时任务描述
|
||||
*
|
||||
* @param description 任务描述
|
||||
* @return r
|
||||
*/
|
||||
public R setDescription(String description) {
|
||||
reqDTO.setDescription(description);
|
||||
return r;
|
||||
return ValidatorUtils.validateEntity(Add.class, getReqDTO());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
public class BroadcastAddHandler extends AddHandler<BroadcastAddHandler> {
|
||||
|
||||
public BroadcastAddHandler() {
|
||||
this(JobTaskTypeEnum.BROADCAST, null);
|
||||
this(JobTaskTypeEnum.BROADCAST);
|
||||
}
|
||||
|
||||
public BroadcastAddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
super(taskType, shardNum);
|
||||
public BroadcastAddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
// 广播模式只允许并发为 1
|
||||
setParallelNum(1);
|
||||
// 广播模式采用轮询模式
|
||||
|
@ -11,11 +11,11 @@ import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
public class ClusterAddHandler extends AddHandler<ClusterAddHandler> {
|
||||
|
||||
public ClusterAddHandler() {
|
||||
this(JobTaskTypeEnum.CLUSTER, null);
|
||||
this(JobTaskTypeEnum.CLUSTER);
|
||||
}
|
||||
|
||||
public ClusterAddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
super(taskType, shardNum);
|
||||
public ClusterAddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
// 集群模式只允许并发为 1
|
||||
setParallelNum(1);
|
||||
setR(this);
|
||||
|
@ -11,11 +11,11 @@ import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
public class MapAddHandler extends AddHandler<MapAddHandler> {
|
||||
|
||||
public MapAddHandler() {
|
||||
this(JobTaskTypeEnum.MAP, null);
|
||||
this(JobTaskTypeEnum.MAP);
|
||||
}
|
||||
|
||||
public MapAddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
super(taskType, shardNum);
|
||||
public MapAddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
setRouteKey(AllocationAlgorithmEnum.ROUND);
|
||||
setR(this);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.add;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.update.MapReduceUpdateHandler;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
/**
|
||||
@ -10,12 +11,12 @@ import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
*/
|
||||
public class MapReduceAddHandler extends AddHandler<MapReduceAddHandler> {
|
||||
|
||||
public MapReduceAddHandler(Integer shardNum) {
|
||||
this(JobTaskTypeEnum.MAP_REDUCE, shardNum);
|
||||
public MapReduceAddHandler() {
|
||||
this(JobTaskTypeEnum.MAP_REDUCE);
|
||||
}
|
||||
|
||||
public MapReduceAddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
super(taskType, shardNum);
|
||||
public MapReduceAddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
setRouteKey(AllocationAlgorithmEnum.ROUND);
|
||||
setR(this);
|
||||
}
|
||||
@ -29,4 +30,9 @@ public class MapReduceAddHandler extends AddHandler<MapReduceAddHandler> {
|
||||
public MapReduceAddHandler setParallelNum(Integer parallelNum) {
|
||||
return super.setParallelNum(parallelNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapReduceAddHandler setShardNum(Integer shardNum) {
|
||||
return super.setShardNum(shardNum);
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
public class ShardingAddHandler extends AddHandler<ShardingAddHandler> {
|
||||
|
||||
public ShardingAddHandler() {
|
||||
this(JobTaskTypeEnum.SHARDING, null);
|
||||
this(JobTaskTypeEnum.SHARDING);
|
||||
}
|
||||
|
||||
public ShardingAddHandler(JobTaskTypeEnum taskType, Integer shardNum) {
|
||||
super(taskType, shardNum);
|
||||
public ShardingAddHandler(JobTaskTypeEnum taskType) {
|
||||
super(taskType);
|
||||
setRouteKey(AllocationAlgorithmEnum.ROUND);
|
||||
setR(this);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import cn.hutool.core.lang.Pair;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobResponseVO;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -29,7 +31,10 @@ public class RequestQueryHandler extends AbstractRequestHandler<JobResponseVO> {
|
||||
|
||||
@Override
|
||||
protected JobResponseVO doExecute() {
|
||||
Object data = client.getJobDetail(queryJobId).getData();
|
||||
Result<Object> result = client.getJobDetail(queryJobId);
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
Object data = result.getData();
|
||||
Assert.isTrue(Objects.nonNull(data), () -> new SnailJobClientException("获取[{}]任务详情失败", queryJobId));
|
||||
return JsonUtil.parseObject(JsonUtil.toJsonString(data), JobResponseVO.class);
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.trigger;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.enums.JobTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
|
||||
public class RequestTriggerJobHandler extends AbstractRequestHandler<Boolean> {
|
||||
public class TriggerJobHandler extends AbstractRequestHandler<Boolean> {
|
||||
private final Long triggerJobId;
|
||||
// 1: job; 2: workflow
|
||||
private final int triggerType;
|
||||
|
||||
public RequestTriggerJobHandler(Long triggerJobId, int triggerType) {
|
||||
|
||||
public TriggerJobHandler(Long triggerJobId) {
|
||||
this.triggerJobId = triggerJobId;
|
||||
this.triggerType = triggerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,13 +27,10 @@ public class RequestTriggerJobHandler extends AbstractRequestHandler<Boolean> {
|
||||
|
||||
@Override
|
||||
protected Boolean doExecute() {
|
||||
if (triggerType == JobTypeEnum.JOB.getType()) {
|
||||
return (Boolean) client.triggerJob(triggerJobId).getData();
|
||||
}
|
||||
if (triggerType == JobTypeEnum.WORKFLOW.getType()) {
|
||||
return (Boolean) client.triggerWorkFlow(triggerJobId).getData();
|
||||
}
|
||||
throw new SnailJobClientException("snail job openapi check error");
|
||||
Result<Object> result = client.triggerJob(triggerJobId);
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
return (Boolean)result.getData();
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,39 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.trigger;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
|
||||
public class TriggerWorkflowHandler extends AbstractRequestHandler<Boolean> {
|
||||
private final Long triggerJobId;
|
||||
|
||||
public TriggerWorkflowHandler(Long triggerJobId) {
|
||||
this.triggerJobId = triggerJobId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterExecute(Boolean aBoolean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeExecute() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doExecute() {
|
||||
Result<Object> result = client.triggerWorkFlow(triggerJobId);
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
return (Boolean) result.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Boolean, String> checkRequest() {
|
||||
return Pair.of(triggerJobId != null && !Long.valueOf(0).equals(triggerJobId), "triggerJobId不能为null并且必须大于0");
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
public class BroadcastUpdateHandler extends UpdateHandler<BroadcastUpdateHandler>{
|
||||
|
||||
public BroadcastUpdateHandler(Long jobId) {
|
||||
super(jobId);
|
||||
super(JobTaskTypeEnum.BROADCAST, jobId);
|
||||
setR(this);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
public class ClusterUpdateHandler extends UpdateHandler<ClusterUpdateHandler> {
|
||||
|
||||
public ClusterUpdateHandler(Long jobId) {
|
||||
super(jobId);
|
||||
super(JobTaskTypeEnum.CLUSTER, jobId);
|
||||
setR(this);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
public class MapReduceUpdateHandler extends UpdateHandler<MapReduceUpdateHandler> {
|
||||
|
||||
public MapReduceUpdateHandler(Long jobId) {
|
||||
super(jobId);
|
||||
super(JobTaskTypeEnum.MAP_REDUCE, jobId);
|
||||
setR(this);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
public class MapUpdateHandler extends UpdateHandler<MapUpdateHandler> {
|
||||
|
||||
public MapUpdateHandler(Long jobId) {
|
||||
super(jobId);
|
||||
super(JobTaskTypeEnum.MAP, jobId);
|
||||
setR(this);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
|
||||
public class ShardingUpdateHandler extends UpdateHandler<ShardingUpdateHandler>{
|
||||
|
||||
public ShardingUpdateHandler(Long jobId) {
|
||||
super(jobId);
|
||||
super(JobTaskTypeEnum.SHARDING, jobId);
|
||||
setR(this);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-10-20 11:59:02
|
||||
* @since sj_1.2.0
|
||||
*/
|
||||
public interface Update {
|
||||
}
|
@ -1,30 +1,23 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractParamsHandler;
|
||||
import com.aizuda.snailjob.client.job.core.util.ValidatorUtils;
|
||||
import com.aizuda.snailjob.common.core.enums.BlockStrategyEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobArgsTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobTaskTypeEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public abstract class UpdateHandler<R> extends AbstractRequestHandler<Boolean> {
|
||||
private final RequestUpdateJobDTO reqDTO;
|
||||
@Setter
|
||||
private R r;
|
||||
public abstract class UpdateHandler<H> extends AbstractParamsHandler<H, Boolean> {
|
||||
|
||||
public UpdateHandler(Long jobId) {
|
||||
this.reqDTO = new RequestUpdateJobDTO();
|
||||
public UpdateHandler(JobTaskTypeEnum typeEnum, Long jobId) {
|
||||
super(typeEnum);
|
||||
// 更新必须要id
|
||||
reqDTO.setId(jobId);
|
||||
setId(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,7 +27,7 @@ public abstract class UpdateHandler<R> extends AbstractRequestHandler<Boolean> {
|
||||
|
||||
@Override
|
||||
protected void beforeExecute() {
|
||||
if (reqDTO.getTriggerType() == TriggerTypeEnum.WORK_FLOW.getType()) {
|
||||
if (getReqDTO().getTriggerType() == TriggerTypeEnum.WORK_FLOW.getType()) {
|
||||
// 工作流没有调度时间
|
||||
setTriggerInterval("*");
|
||||
}
|
||||
@ -42,204 +35,15 @@ public abstract class UpdateHandler<R> extends AbstractRequestHandler<Boolean> {
|
||||
|
||||
@Override
|
||||
protected Boolean doExecute() {
|
||||
return (Boolean) client.updateJob(reqDTO).getData();
|
||||
Result<Object> result = client.updateJob(getReqDTO());
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
return (Boolean) result.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Boolean, String> checkRequest() {
|
||||
return ValidatorUtils.validateEntity(reqDTO);
|
||||
return ValidatorUtils.validateEntity(Update.class, getReqDTO());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改Reduce的分片数
|
||||
* 只允许MAP_REDUCE设置
|
||||
*
|
||||
* @param shardNum
|
||||
* @return
|
||||
*/
|
||||
protected R setShardNum(Integer shardNum) {
|
||||
// 设置分片
|
||||
if (shardNum != null) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
map.put(SHARD_NUM, shardNum);
|
||||
setArgsStr(map);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改任务名称
|
||||
*
|
||||
* @param jobName
|
||||
* @return
|
||||
*/
|
||||
public R setJobName(String jobName) {
|
||||
reqDTO.setJobName(jobName);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改时会直接覆盖之前的任务参数
|
||||
* 修改参数
|
||||
*
|
||||
* @param argsStr
|
||||
* @return
|
||||
*/
|
||||
private R setArgsStr(Map<String, Object> argsStr) {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(reqDTO.getArgsStr())) {
|
||||
args = JsonUtil.parseHashMap(reqDTO.getArgsStr());
|
||||
}
|
||||
args.putAll(argsStr);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(args));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.JSON.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改时会直接覆盖之前的任务参数
|
||||
* 添加参数,可支持多次添加
|
||||
* 静态分片不可使用该方法
|
||||
*
|
||||
* @param argsKey 参数名
|
||||
* @param argsValue 参数值
|
||||
* @return
|
||||
*/
|
||||
protected R addArgsStr(String argsKey, Object argsValue) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(reqDTO.getArgsStr())) {
|
||||
map = JsonUtil.parseHashMap(reqDTO.getArgsStr());
|
||||
}
|
||||
map.put(argsKey, argsValue);
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(map));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.JSON.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加静态分片相关参数
|
||||
* 只有静态分片任务可用
|
||||
*
|
||||
* @param shardingValue
|
||||
* @return
|
||||
*/
|
||||
protected R addShardingArgs(String[] shardingValue) {
|
||||
reqDTO.setArgsStr(JsonUtil.toJsonString(shardingValue));
|
||||
reqDTO.setArgsType(JobArgsTypeEnum.TEXT.getArgsType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改路由
|
||||
*
|
||||
* @param algorithmEnum
|
||||
* @return
|
||||
*/
|
||||
protected R setRouteKey(AllocationAlgorithmEnum algorithmEnum) {
|
||||
reqDTO.setRouteKey(algorithmEnum.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改相关执行器
|
||||
*
|
||||
* @param executorInfo
|
||||
* @return
|
||||
*/
|
||||
public R setExecutorInfo(String executorInfo) {
|
||||
reqDTO.setExecutorInfo(executorInfo);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改调度类型
|
||||
*
|
||||
* @param triggerType
|
||||
* @return
|
||||
*/
|
||||
public R setTriggerType(TriggerTypeEnum triggerType) {
|
||||
reqDTO.setTriggerType(triggerType.getType());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改调度时间
|
||||
* 单位:秒
|
||||
* 工作流无需配置
|
||||
*
|
||||
* @param triggerInterval
|
||||
* @return
|
||||
*/
|
||||
public R setTriggerInterval(String triggerInterval) {
|
||||
reqDTO.setTriggerInterval(triggerInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改阻塞策略
|
||||
*
|
||||
* @param blockStrategy
|
||||
* @return
|
||||
*/
|
||||
public R setBlockStrategy(BlockStrategyEnum blockStrategy) {
|
||||
reqDTO.setBlockStrategy(blockStrategy.getBlockStrategy());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改执行器超时时间
|
||||
*
|
||||
* @param executorTimeout
|
||||
* @return
|
||||
*/
|
||||
public R setExecutorTimeout(Integer executorTimeout) {
|
||||
reqDTO.setExecutorTimeout(executorTimeout);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改任务最大重试次数
|
||||
*
|
||||
* @param maxRetryTimes
|
||||
* @return
|
||||
*/
|
||||
public R setMaxRetryTimes(Integer maxRetryTimes) {
|
||||
reqDTO.setMaxRetryTimes(maxRetryTimes);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改重试间隔
|
||||
*
|
||||
* @param retryInterval
|
||||
* @return
|
||||
*/
|
||||
public R setRetryInterval(Integer retryInterval) {
|
||||
reqDTO.setRetryInterval(retryInterval);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改并发数量
|
||||
*
|
||||
* @param parallelNum
|
||||
* @return
|
||||
*/
|
||||
protected R setParallelNum(Integer parallelNum) {
|
||||
reqDTO.setParallelNum(parallelNum);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改定时任务描述
|
||||
*
|
||||
* @param description
|
||||
* @return
|
||||
*/
|
||||
public R setDescription(String description) {
|
||||
reqDTO.setDescription(description);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateStatusDTO;
|
||||
import com.aizuda.snailjob.client.job.core.enums.JobTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.client.job.core.util.ValidatorUtils;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
|
||||
|
||||
public class RequestUpdateStatusHandler extends AbstractRequestHandler<Boolean> {
|
||||
public class UpdateJobStatusHandler extends AbstractRequestHandler<Boolean> {
|
||||
private final RequestUpdateStatusDTO statusDTO;
|
||||
// 1: job; 2: workflow
|
||||
private final int type;
|
||||
|
||||
public RequestUpdateStatusHandler(Long id, int type) {
|
||||
public UpdateJobStatusHandler(Long id) {
|
||||
this.statusDTO = new RequestUpdateStatusDTO();
|
||||
this.type = type;
|
||||
setId(id);
|
||||
}
|
||||
|
||||
@ -32,13 +30,10 @@ public class RequestUpdateStatusHandler extends AbstractRequestHandler<Boolean>
|
||||
|
||||
@Override
|
||||
protected Boolean doExecute() {
|
||||
if (type == JobTypeEnum.JOB.getType()) {
|
||||
return (Boolean) client.updateJobStatus(statusDTO).getData();
|
||||
}
|
||||
if (type == JobTypeEnum.WORKFLOW.getType()) {
|
||||
return (Boolean) client.updateWorkFlowStatus(statusDTO).getData();
|
||||
}
|
||||
throw new SnailJobClientException("snail job openapi check error");
|
||||
Result<Object> result = client.updateJobStatus(statusDTO);
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
return (Boolean) result.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +47,7 @@ public class RequestUpdateStatusHandler extends AbstractRequestHandler<Boolean>
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private RequestUpdateStatusHandler setId(Long id) {
|
||||
private UpdateJobStatusHandler setId(Long id) {
|
||||
this.statusDTO.setId(id);
|
||||
return this;
|
||||
}
|
||||
@ -63,7 +58,7 @@ public class RequestUpdateStatusHandler extends AbstractRequestHandler<Boolean>
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public RequestUpdateStatusHandler setStatus(StatusEnum status) {
|
||||
public UpdateJobStatusHandler setStatus(StatusEnum status) {
|
||||
this.statusDTO.setJobStatus(status.getStatus());
|
||||
return this;
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.aizuda.snailjob.client.job.core.handler.update;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateStatusDTO;
|
||||
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||
import com.aizuda.snailjob.client.job.core.util.ValidatorUtils;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
|
||||
|
||||
public class UpdateWorkflowStatusHandler extends AbstractRequestHandler<Boolean> {
|
||||
private final RequestUpdateStatusDTO statusDTO;
|
||||
|
||||
public UpdateWorkflowStatusHandler(Long id) {
|
||||
this.statusDTO = new RequestUpdateStatusDTO();
|
||||
setId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterExecute(Boolean aBoolean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeExecute() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doExecute() {
|
||||
Result<Object> result = client.updateWorkFlowStatus(statusDTO);
|
||||
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||
() -> new SnailJobClientException(result.getMessage()));
|
||||
return (Boolean) result.getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Boolean, String> checkRequest() {
|
||||
return ValidatorUtils.validateEntity(statusDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务/工作流ID
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private UpdateWorkflowStatusHandler setId(Long id) {
|
||||
this.statusDTO.setId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
*
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public UpdateWorkflowStatusHandler setStatus(StatusEnum status) {
|
||||
this.statusDTO.setJobStatus(status.getStatus());
|
||||
return this;
|
||||
}
|
||||
}
|
@ -2,17 +2,16 @@ package com.aizuda.snailjob.client.job.core.openapi;
|
||||
|
||||
import com.aizuda.snailjob.client.common.annotation.Mapping;
|
||||
import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestAddJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestAddOrUpdateJobDTO;
|
||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateStatusDTO;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
|
||||
public interface OpenApiClient {
|
||||
@Mapping(method = RequestMethod.POST, path = "/api/job/add")
|
||||
Result<Object> addJob(RequestAddJobDTO requestAddJobDTO);
|
||||
Result<Object> addJob(RequestAddOrUpdateJobDTO requestAddOrUpdateJobDTO);
|
||||
|
||||
@Mapping(method = RequestMethod.POST, path = "/api/job/update")
|
||||
Result<Object> updateJob(RequestUpdateJobDTO requestUpdateJobDTO);
|
||||
Result<Object> updateJob(RequestAddOrUpdateJobDTO requestUpdateJobDTO);
|
||||
|
||||
@Mapping(method = RequestMethod.POST, path = "/api/job/getJobDetail")
|
||||
Result<Object> getJobDetail(Long jobId);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.aizuda.snailjob.client.job.core.openapi;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.enums.JobTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.handler.add.*;
|
||||
import com.aizuda.snailjob.client.job.core.handler.query.RequestQueryHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.trigger.RequestTriggerJobHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerJobHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerWorkflowHandler;
|
||||
import com.aizuda.snailjob.client.job.core.handler.update.*;
|
||||
|
||||
/**
|
||||
@ -54,11 +54,10 @@ public final class SnailJobOpenApi {
|
||||
/**
|
||||
* 添加MapReduce定时任务
|
||||
*
|
||||
* @param shardNum Reduce数量
|
||||
* @return {@link MapReduceAddHandler}
|
||||
*/
|
||||
public static MapReduceAddHandler addMapReduceJob(Integer shardNum) {
|
||||
return new MapReduceAddHandler(shardNum);
|
||||
public static MapReduceAddHandler addMapReduceJob() {
|
||||
return new MapReduceAddHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,39 +124,39 @@ public final class SnailJobOpenApi {
|
||||
* 手动触发定时任务
|
||||
*
|
||||
* @param jobId 定时任务ID
|
||||
* @return {@link RequestTriggerJobHandler}
|
||||
* @return {@link TriggerJobHandler}
|
||||
*/
|
||||
public static RequestTriggerJobHandler triggerJob(Long jobId) {
|
||||
return new RequestTriggerJobHandler(jobId, JobTypeEnum.JOB.getType());
|
||||
public static TriggerJobHandler triggerJob(Long jobId) {
|
||||
return new TriggerJobHandler(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动触发工作流任务
|
||||
*
|
||||
* @param id 工作流任务ID
|
||||
* @return {@link RequestTriggerJobHandler}
|
||||
* @return {@link TriggerWorkflowHandler}
|
||||
*/
|
||||
public static RequestTriggerJobHandler triggerWorkFlow(Long id) {
|
||||
return new RequestTriggerJobHandler(id, JobTypeEnum.WORKFLOW.getType());
|
||||
public static TriggerWorkflowHandler triggerWorkFlow(Long id) {
|
||||
return new TriggerWorkflowHandler(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务状态
|
||||
*
|
||||
* @param jobId 任务ID
|
||||
* @return {@link RequestUpdateStatusHandler}
|
||||
* @return {@link UpdateJobStatusHandler}
|
||||
*/
|
||||
public static RequestUpdateStatusHandler updateJobStatus(Long jobId) {
|
||||
return new RequestUpdateStatusHandler(jobId, JobTypeEnum.JOB.getType());
|
||||
public static UpdateJobStatusHandler updateJobStatus(Long jobId) {
|
||||
return new UpdateJobStatusHandler(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新工作流任务状态
|
||||
*
|
||||
* @param workFlowId 工作流ID
|
||||
* @return {@link RequestUpdateStatusHandler}
|
||||
* @return {@link UpdateJobStatusHandler}
|
||||
*/
|
||||
public static RequestUpdateStatusHandler updateWorkFlowStatus(Long workFlowId) {
|
||||
return new RequestUpdateStatusHandler(workFlowId, JobTypeEnum.WORKFLOW.getType());
|
||||
public static UpdateWorkflowStatusHandler updateWorkFlowStatus(Long workFlowId) {
|
||||
return new UpdateWorkflowStatusHandler(workFlowId);
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,23 @@ public class ValidatorUtils {
|
||||
validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
}
|
||||
|
||||
public static Pair<Boolean, String> validateEntity(Object object) {
|
||||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object);
|
||||
return validateEntity(constraintViolations, object);
|
||||
}
|
||||
|
||||
public static Pair<Boolean, String> validateEntity(Class<?> group, Object object) {
|
||||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, group);
|
||||
return validateEntity(constraintViolations, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验对象
|
||||
*
|
||||
* @param object 待校验对象
|
||||
* @throws SnailJobClientException 校验不通过,则报SnailJobClientException异常
|
||||
*/
|
||||
public static Pair<Boolean, String> validateEntity(Object object) {
|
||||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object);
|
||||
public static Pair<Boolean, String> validateEntity( Set<ConstraintViolation<Object>> constraintViolations, Object object) {
|
||||
if (!constraintViolations.isEmpty()) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (ConstraintViolation<Object> constraint : constraintViolations) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.aizuda.snailjob.server.common.util;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.aizuda.snailjob.common.core.util.CronExpression;
|
||||
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.time.Duration;
|
||||
@ -38,6 +40,7 @@ public class CronUtils {
|
||||
|
||||
public static long getExecuteInterval(String cron) {
|
||||
List<String> executeTimeByCron = getExecuteTimeByCron(cron, 2);
|
||||
Assert.isTrue(!executeTimeByCron.isEmpty(), () -> new SnailJobServerException("[{}]表达式解析有误", cron));
|
||||
LocalDateTime first = LocalDateTime.parse(executeTimeByCron.get(0), DateUtils.NORM_DATETIME_PATTERN);
|
||||
LocalDateTime second = LocalDateTime.parse(executeTimeByCron.get(1), DateUtils.NORM_DATETIME_PATTERN);
|
||||
Duration duration = Duration.between(first, second);
|
||||
|
Loading…
Reference in New Issue
Block a user