fix: 2.5.0

1. 支持任务关闭可以手动支持任务
2. 修复任务失败状态没有统计问题
3. 修复重试模块看板更新统计
This commit is contained in:
byteblogs168 2023-12-06 18:31:22 +08:00
parent 2bafc083a5
commit cce2d9d633
13 changed files with 91 additions and 25 deletions

View File

@ -47,9 +47,9 @@
operation_reason AS operationReason, operation_reason AS operationReason,
COUNT(operation_reason) AS operationReasonTotal, COUNT(operation_reason) AS operationReasonTotal,
SUM(CASE WHEN (task_batch_status = 3) THEN 1 ELSE 0 END) AS successNum, SUM(CASE WHEN (task_batch_status = 3) THEN 1 ELSE 0 END) AS successNum,
SUM(CASE WHEN (operation_reason IN (2, 3)) THEN 1 ELSE 0 END) AS cancelNum, SUM(CASE WHEN (task_batch_status = 6) THEN 1 ELSE 0 END) AS cancelNum,
SUM(CASE WHEN (operation_reason IN (1, 5, 8)) THEN 1 ELSE 0 END) AS stopNum, SUM(CASE WHEN (task_batch_status = 5) THEN 1 ELSE 0 END) AS stopNum,
SUM(CASE WHEN (operation_reason IN (4, 6, 7)) THEN 1 ELSE 0 END) AS failNum SUM(CASE WHEN (task_batch_status = 4) THEN 1 ELSE 0 END) AS failNum
FROM job_task_batch FROM job_task_batch
WHERE create_dt BETWEEN #{from} AND #{to} WHERE create_dt BETWEEN #{from} AND #{to}
GROUP BY namespace_id, group_name, job_id, task_batch_status, operation_reason GROUP BY namespace_id, group_name, job_id, task_batch_status, operation_reason

View File

@ -33,10 +33,10 @@
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
namespace_id = values(`namespace_id`), running_num = values(`running_num`),
group_name = values(`group_name`), finish_num = values(`finish_num`),
scene_name = values(`scene_name`), max_count_num = values(`max_count_num`),
trigger_at = values(`trigger_at`) suspend_num = values(`suspend_num`)
</insert> </insert>
<select id="retryTask" <select id="retryTask"

View File

@ -0,0 +1,40 @@
package com.aizuda.easy.retry.server.common.enums;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* job 触发器类型枚举
*
* @author: xiaowoniu
* @date : 2023-12-06 17:21
* @since : 2.5.0
*/
@Getter
@AllArgsConstructor
public enum JobTriggerTypeEnum {
AUTO(1, "自动触发"),
MANUAL(2, "手动触发");
private final Integer type;
private final String desc;
/**
* 根据给定的类型获取对应的触发器类型枚举
*
* @param type 触发器类型的整数值
* @return 对应的触发器类型枚举
* @throws EasyRetryServerException 当给定的类型不是有效的枚举类型时抛出异常
*/
public static JobTriggerTypeEnum get(Integer type) {
for (JobTriggerTypeEnum jobTriggerTypeEnum : JobTriggerTypeEnum.values()) {
if(jobTriggerTypeEnum.getType().equals(type)) {
return jobTriggerTypeEnum;
}
}
throw new EasyRetryServerException("无效枚举类型.[{}]", type);
}
}

View File

@ -52,4 +52,9 @@ public class JobTaskPrepareDTO {
private boolean onlyTimeoutCheck; private boolean onlyTimeoutCheck;
/**
* 触发类似 1auto 2manual
*/
private Integer triggerType;
} }

View File

@ -12,4 +12,8 @@ public class JobTimerTaskDTO {
private Long taskBatchId; private Long taskBatchId;
private Long jobId; private Long jobId;
/**
* 触发类似 1auto 2manual
*/
private Integer triggerType;
} }

View File

@ -11,5 +11,9 @@ public class TaskExecuteDTO {
private Long jobId; private Long jobId;
private Long taskBatchId; private Long taskBatchId;
/**
* 触发类似 1auto 2manual
*/
private Integer triggerType;
} }

View File

@ -11,6 +11,7 @@ import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.common.WaitStrategy; import com.aizuda.easy.retry.server.common.WaitStrategy;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator; import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable; import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.enums.JobTriggerTypeEnum;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException; import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.strategy.WaitStrategies; import com.aizuda.easy.retry.server.common.strategy.WaitStrategies;
import com.aizuda.easy.retry.server.common.util.DateUtils; import com.aizuda.easy.retry.server.common.util.DateUtils;
@ -86,10 +87,13 @@ public class JobExecutorActor extends AbstractActor {
private void doExecute(final TaskExecuteDTO taskExecute) { private void doExecute(final TaskExecuteDTO taskExecute) {
Job job = jobMapper.selectOne(new LambdaQueryWrapper<Job>() LambdaQueryWrapper<Job> queryWrapper = new LambdaQueryWrapper<Job>();
.eq(Job::getJobStatus, StatusEnum.YES.getStatus()) // 自动的校验任务必须是开启状态手动触发无需校验
.eq(Job::getId, taskExecute.getJobId()) if (JobTriggerTypeEnum.AUTO.getType().equals(taskExecute.getTriggerType())) {
); queryWrapper.eq(Job::getJobStatus, StatusEnum.YES.getStatus());
}
Job job = jobMapper.selectOne(queryWrapper.eq(Job::getId, taskExecute.getJobId()));
try { try {
@ -146,7 +150,7 @@ public class JobExecutorActor extends AbstractActor {
} }
private void doHandlerResidentTask(Job job, TaskExecuteDTO taskExecuteDTO) { private void doHandlerResidentTask(Job job, TaskExecuteDTO taskExecuteDTO) {
if (Objects.isNull(job)) { if (Objects.isNull(job) || JobTriggerTypeEnum.MANUAL.getType().equals(taskExecuteDTO.getTriggerType())) {
return; return;
} }
@ -156,6 +160,7 @@ public class JobExecutorActor extends AbstractActor {
JobTimerTaskDTO jobTimerTaskDTO = new JobTimerTaskDTO(); JobTimerTaskDTO jobTimerTaskDTO = new JobTimerTaskDTO();
jobTimerTaskDTO.setJobId(taskExecuteDTO.getJobId()); jobTimerTaskDTO.setJobId(taskExecuteDTO.getJobId());
jobTimerTaskDTO.setTaskBatchId(taskExecuteDTO.getTaskBatchId()); jobTimerTaskDTO.setTaskBatchId(taskExecuteDTO.getTaskBatchId());
jobTimerTaskDTO.setTriggerType(JobTriggerTypeEnum.AUTO.getType());
ResidentJobTimerTask timerTask = new ResidentJobTimerTask(jobTimerTaskDTO, job); ResidentJobTimerTask timerTask = new ResidentJobTimerTask(jobTimerTaskDTO, job);
WaitStrategy waitStrategy = WaitStrategies.WaitStrategyEnum.getWaitStrategy(job.getTriggerType()); WaitStrategy waitStrategy = WaitStrategies.WaitStrategyEnum.getWaitStrategy(job.getTriggerType());

View File

@ -11,6 +11,7 @@ import com.aizuda.easy.retry.server.common.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.common.config.SystemProperties; import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.dto.PartitionTask; import com.aizuda.easy.retry.server.common.dto.PartitionTask;
import com.aizuda.easy.retry.server.common.dto.ScanTask; import com.aizuda.easy.retry.server.common.dto.ScanTask;
import com.aizuda.easy.retry.server.common.enums.JobTriggerTypeEnum;
import com.aizuda.easy.retry.server.common.strategy.WaitStrategies; import com.aizuda.easy.retry.server.common.strategy.WaitStrategies;
import com.aizuda.easy.retry.server.common.util.DateUtils; import com.aizuda.easy.retry.server.common.util.DateUtils;
import com.aizuda.easy.retry.server.common.util.PartitionTaskUtils; import com.aizuda.easy.retry.server.common.util.PartitionTaskUtils;
@ -29,7 +30,6 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -90,6 +90,7 @@ public class ScanJobTaskActor extends AbstractActor {
for (final JobTaskPrepareDTO waitExecJob : waitExecJobs) { for (final JobTaskPrepareDTO waitExecJob : waitExecJobs) {
// 执行预处理阶段 // 执行预处理阶段
ActorRef actorRef = ActorGenerator.jobTaskPrepareActor(); ActorRef actorRef = ActorGenerator.jobTaskPrepareActor();
waitExecJob.setTriggerType(JobTriggerTypeEnum.AUTO.getType());
actorRef.tell(waitExecJob, actorRef); actorRef.tell(waitExecJob, actorRef);
} }
} }

View File

@ -64,6 +64,7 @@ public class JobTaskBatchGenerator {
JobTimerTaskDTO jobTimerTaskDTO = new JobTimerTaskDTO(); JobTimerTaskDTO jobTimerTaskDTO = new JobTimerTaskDTO();
jobTimerTaskDTO.setTaskBatchId(jobTaskBatch.getId()); jobTimerTaskDTO.setTaskBatchId(jobTaskBatch.getId());
jobTimerTaskDTO.setJobId(context.getJobId()); jobTimerTaskDTO.setJobId(context.getJobId());
jobTimerTaskDTO.setTriggerType(context.getTriggerType());
JobTimerWheel.register(jobTaskBatch.getId(), JobTimerWheel.register(jobTaskBatch.getId(),
new JobTimerTask(jobTimerTaskDTO), delay, TimeUnit.MILLISECONDS); new JobTimerTask(jobTimerTaskDTO), delay, TimeUnit.MILLISECONDS);

View File

@ -40,5 +40,10 @@ public class JobTaskBatchGeneratorContext {
*/ */
private Integer taskBatchStatus; private Integer taskBatchStatus;
/**
* 触发类似 1auto 2manual
*/
private Integer triggerType;
} }

View File

@ -31,6 +31,7 @@ public class JobTimerTask implements TimerTask {
TaskExecuteDTO taskExecuteDTO = new TaskExecuteDTO(); TaskExecuteDTO taskExecuteDTO = new TaskExecuteDTO();
taskExecuteDTO.setTaskBatchId(jobTimerTaskDTO.getTaskBatchId()); taskExecuteDTO.setTaskBatchId(jobTimerTaskDTO.getTaskBatchId());
taskExecuteDTO.setJobId(jobTimerTaskDTO.getJobId()); taskExecuteDTO.setJobId(jobTimerTaskDTO.getJobId());
taskExecuteDTO.setTriggerType(jobTimerTaskDTO.getTriggerType());
ActorRef actorRef = ActorGenerator.jobTaskExecutorActor(); ActorRef actorRef = ActorGenerator.jobTaskExecutorActor();
actorRef.tell(taskExecuteDTO, actorRef); actorRef.tell(taskExecuteDTO, actorRef);

View File

@ -2,6 +2,7 @@ package com.aizuda.easy.retry.server.job.task.support.timer;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator; import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.enums.JobTriggerTypeEnum;
import com.aizuda.easy.retry.server.job.task.dto.JobTaskPrepareDTO; import com.aizuda.easy.retry.server.job.task.dto.JobTaskPrepareDTO;
import com.aizuda.easy.retry.server.job.task.dto.JobTimerTaskDTO; import com.aizuda.easy.retry.server.job.task.dto.JobTimerTaskDTO;
import com.aizuda.easy.retry.server.job.task.support.JobTaskConverter; import com.aizuda.easy.retry.server.job.task.support.JobTaskConverter;
@ -29,6 +30,7 @@ public class ResidentJobTimerTask implements TimerTask {
// 清除时间轮的缓存 // 清除时间轮的缓存
JobTimerWheel.clearCache(jobTimerTaskDTO.getTaskBatchId()); JobTimerWheel.clearCache(jobTimerTaskDTO.getTaskBatchId());
JobTaskPrepareDTO jobTaskPrepare = JobTaskConverter.INSTANCE.toJobTaskPrepare(job); JobTaskPrepareDTO jobTaskPrepare = JobTaskConverter.INSTANCE.toJobTaskPrepare(job);
jobTaskPrepare.setTriggerType(JobTriggerTypeEnum.AUTO.getType());
// 执行预处理阶段 // 执行预处理阶段
ActorRef actorRef = ActorGenerator.jobTaskPrepareActor(); ActorRef actorRef = ActorGenerator.jobTaskPrepareActor();
actorRef.tell(jobTaskPrepare, actorRef); actorRef.tell(jobTaskPrepare, actorRef);

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.common.core.enums.StatusEnum; import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.server.common.WaitStrategy; import com.aizuda.easy.retry.server.common.WaitStrategy;
import com.aizuda.easy.retry.server.common.config.SystemProperties; import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.enums.JobTriggerTypeEnum;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException; import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.strategy.WaitStrategies; import com.aizuda.easy.retry.server.common.strategy.WaitStrategies;
import com.aizuda.easy.retry.server.common.util.CronUtils; import com.aizuda.easy.retry.server.common.util.CronUtils;
@ -22,11 +23,9 @@ import com.aizuda.easy.retry.server.web.model.response.JobResponseVO;
import com.aizuda.easy.retry.server.web.service.JobService; import com.aizuda.easy.retry.server.web.service.JobService;
import com.aizuda.easy.retry.server.web.service.convert.JobConverter; import com.aizuda.easy.retry.server.web.service.convert.JobConverter;
import com.aizuda.easy.retry.server.web.service.convert.JobResponseVOConverter; import com.aizuda.easy.retry.server.web.service.convert.JobResponseVOConverter;
import com.aizuda.easy.retry.server.web.service.convert.SceneConfigResponseVOConverter;
import com.aizuda.easy.retry.server.web.util.UserSessionUtils; import com.aizuda.easy.retry.server.web.util.UserSessionUtils;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.JobMapper; import com.aizuda.easy.retry.template.datasource.persistence.mapper.JobMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.Job; import com.aizuda.easy.retry.template.datasource.persistence.po.Job;
import com.aizuda.easy.retry.template.datasource.persistence.po.SceneConfig;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -34,8 +33,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@ -213,6 +210,7 @@ public class JobServiceImpl implements JobService {
JobTaskPrepareDTO jobTaskPrepare = JobTaskConverter.INSTANCE.toJobTaskPrepare(job); JobTaskPrepareDTO jobTaskPrepare = JobTaskConverter.INSTANCE.toJobTaskPrepare(job);
// 设置now表示立即执行 // 设置now表示立即执行
jobTaskPrepare.setNextTriggerAt(DateUtils.toNowMilli()); jobTaskPrepare.setNextTriggerAt(DateUtils.toNowMilli());
jobTaskPrepare.setTriggerType(JobTriggerTypeEnum.MANUAL.getType());
// 创建批次 // 创建批次
jobPrePareHandler.handler(jobTaskPrepare); jobPrePareHandler.handler(jobTaskPrepare);