feat:(1.3.0-beta1): 定时任务告警优化
This commit is contained in:
parent
ef11025fee
commit
289e24de99
@ -1,5 +1,6 @@
|
||||
package com.aizuda.snailjob.common.core.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -14,6 +15,7 @@ import lombok.Getter;
|
||||
public enum JobNotifySceneEnum {
|
||||
|
||||
/********************************Job****************************************/
|
||||
NONE(0, StrUtil.EMPTY, NodeTypeEnum.SERVER),
|
||||
JOB_TASK_ERROR(1, "JOB任务执行失败", NodeTypeEnum.SERVER),
|
||||
JOB_CLIENT_ERROR(2, "客户端执行失败", NodeTypeEnum.CLIENT),
|
||||
JOB_NO_CLIENT_NODES_ERROR(3, "没有可执行的客户端节点", NodeTypeEnum.SERVER),
|
||||
@ -50,8 +52,22 @@ public enum JobNotifySceneEnum {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通知场景描述
|
||||
*
|
||||
* @param notifyScene
|
||||
* @return
|
||||
*/
|
||||
public static JobNotifySceneEnum getJobNotifyScene(Integer notifyScene) {
|
||||
for (JobNotifySceneEnum sceneEnum : JobNotifySceneEnum.values()) {
|
||||
if (sceneEnum.getNotifyScene() == notifyScene) {
|
||||
return sceneEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 标识某个操作的具体原因
|
||||
@ -48,10 +47,14 @@ public enum JobOperationReasonEnum {
|
||||
WORKFLOW_NODE_NO_REQUIRED.getReason(), WORKFLOW_DECISION_FAILED.getReason(),
|
||||
WORKFLOW_CONDITION_NODE_EXECUTION_ERROR.getReason());
|
||||
|
||||
public static JobOperationReasonEnum getByReason(Integer reason) {
|
||||
if (Objects.isNull(reason)) {
|
||||
return NONE;
|
||||
public static JobOperationReasonEnum getWorkflowNotifyScene(Integer notifyScene) {
|
||||
for (JobOperationReasonEnum sceneEnum : JobOperationReasonEnum.values()) {
|
||||
if (sceneEnum.getReason() == notifyScene) {
|
||||
return sceneEnum;
|
||||
}
|
||||
}
|
||||
return Arrays.stream(values()).filter(e -> reason.equals(e.reason)).findFirst().orElse(NONE);
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 通知场景枚举
|
||||
*
|
||||
@ -38,7 +35,7 @@ public enum RetryNotifySceneEnum {
|
||||
/**
|
||||
* 通知场景
|
||||
*/
|
||||
private final Integer notifyScene;
|
||||
private final int notifyScene;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
@ -67,11 +64,14 @@ public enum RetryNotifySceneEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RetryNotifySceneEnum getByDesc(Integer notifyScene) {
|
||||
if (Objects.isNull(notifyScene)) {
|
||||
return NONE;
|
||||
public static RetryNotifySceneEnum getRetryNotifyScene(Integer notifyScene) {
|
||||
for (RetryNotifySceneEnum sceneEnum : RetryNotifySceneEnum.values()) {
|
||||
if (sceneEnum.getNotifyScene() == notifyScene) {
|
||||
return sceneEnum;
|
||||
}
|
||||
}
|
||||
return Arrays.stream(values()).filter(e -> notifyScene.equals(e.getNotifyScene())).findFirst().orElse(NONE);
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public abstract class AbstractJobAlarm<E extends ApplicationEvent> extends Abstr
|
||||
JobAlarmInfo jobAlarmInfo = AlarmInfoConverter.INSTANCE.toJobAlarmInfo(jobBatchResponseDO);
|
||||
JobAlarmInfo alarmInfo = jobAlarmInfoGroupMap.get(jobBatchResponseDO.getId());
|
||||
jobAlarmInfo.setReason(alarmInfo.getReason());
|
||||
jobAlarmInfo.setNotifyScene(alarmInfo.getNotifyScene());
|
||||
|
||||
List<JobAlarmInfo> jobAlarmInfos = jobAlarmInfoMap.getOrDefault(jobNotifyId, Lists.newArrayList());
|
||||
jobAlarmInfos.add(jobAlarmInfo);
|
||||
|
@ -46,6 +46,7 @@ public abstract class AbstractWorkflowAlarm<E extends ApplicationEvent> extends
|
||||
WorkflowAlarmInfo workflowAlarmInfo = AlarmInfoConverter.INSTANCE.toWorkflowAlarmInfo(workflowBatchResponseDO);
|
||||
WorkflowAlarmInfo alarmInfo = workflowAlarmInfoGroupMap.get(workflowAlarmInfo.getId());
|
||||
workflowAlarmInfo.setReason(alarmInfo.getReason());
|
||||
workflowAlarmInfo.setNotifyScene(alarmInfo.getNotifyScene());
|
||||
|
||||
List<WorkflowAlarmInfo> workflowAlarmInfos = workflowAlarmInfoMap.getOrDefault(workflowNotifyId, Lists.newArrayList());
|
||||
workflowAlarmInfos.add(workflowAlarmInfo);
|
||||
|
@ -2,7 +2,6 @@ package com.aizuda.snailjob.server.job.task.support.alarm.listener;
|
||||
|
||||
import com.aizuda.snailjob.common.core.alarm.AlarmContext;
|
||||
import com.aizuda.snailjob.common.core.enums.JobNotifySceneEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.JobOperationReasonEnum;
|
||||
import com.aizuda.snailjob.common.core.util.EnvironmentUtils;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.server.common.alarm.AbstractJobAlarm;
|
||||
@ -81,7 +80,7 @@ public class JobTaskFailAlarmListener extends AbstractJobAlarm<JobTaskFailAlarmE
|
||||
alarmDTO.getGroupName(),
|
||||
alarmDTO.getJobName(),
|
||||
alarmDTO.getExecutorInfo(),
|
||||
JobOperationReasonEnum.getByReason(alarmDTO.getOperationReason()).getDesc(),
|
||||
JobNotifySceneEnum.getJobNotifyScene(alarmDTO.getNotifyScene()).getDesc(),
|
||||
alarmDTO.getReason(),
|
||||
alarmDTO.getArgsStr(),
|
||||
DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN))
|
||||
|
@ -74,7 +74,7 @@ public class WorkflowTaskFailAlarmListener extends AbstractWorkflowAlarm<Workflo
|
||||
alarmDTO.getNamespaceId(),
|
||||
alarmDTO.getGroupName(),
|
||||
alarmDTO.getWorkflowName(),
|
||||
JobOperationReasonEnum.getByReason(alarmDTO.getOperationReason()).getDesc(),
|
||||
JobOperationReasonEnum.getWorkflowNotifyScene(alarmDTO.getOperationReason()).getDesc(),
|
||||
alarmDTO.getReason(),
|
||||
DateUtils.toNowFormat(DateUtils.NORM_DATETIME_PATTERN))
|
||||
.title("{}环境 Workflow任务执行失败", EnvironmentUtils.getActiveProfile());
|
||||
|
@ -69,13 +69,14 @@ public class JobTimeoutCheckTask implements TimerTask<String> {
|
||||
stopJobContext.setWorkflowTaskBatchId(jobTaskBatch.getWorkflowTaskBatchId());
|
||||
instanceInterrupt.stop(stopJobContext);
|
||||
|
||||
String reason = "超时中断.taskBatchId:[" + taskBatchId + "]";
|
||||
SnailSpringContext.getContext().publishEvent(
|
||||
new JobTaskFailAlarmEvent(JobTaskFailAlarmEventDTO.builder()
|
||||
.jobTaskBatchId(taskBatchId)
|
||||
.reason("超时中断.taskBatchId:[" + taskBatchId + "]")
|
||||
.reason(reason)
|
||||
.notifyScene(JobNotifySceneEnum.JOB_TASK_ERROR.getNotifyScene())
|
||||
.build()));
|
||||
SnailJobLog.LOCAL.info("超时中断.taskBatchId:[{}]", taskBatchId);
|
||||
SnailJobLog.LOCAL.info(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,7 +89,7 @@ public class RetryTaskFailAlarmListener extends
|
||||
return AlarmContext.build().text(retryTaskDeadTextMessagesFormatter,
|
||||
EnvironmentUtils.getActiveProfile(),
|
||||
notifyConfig.getNotifyThreshold(),
|
||||
RetryNotifySceneEnum.getByDesc(retryAlarmInfo.getNotifyScene()).getDesc(),
|
||||
RetryNotifySceneEnum.getRetryNotifyScene(retryAlarmInfo.getNotifyScene()).getDesc(),
|
||||
retryAlarmInfo.getNamespaceId(),
|
||||
retryAlarmInfo.getGroupName(),
|
||||
retryAlarmInfo.getExecutorName(),
|
||||
|
Loading…
Reference in New Issue
Block a user