Merge pull request #10848 from dataease/pr@dev-v2@feat_report_task_retry

feat(X-Pack): 定时报告增加失败重试机制 #10171
This commit is contained in:
fit2cloud-chenyw 2024-07-09 12:22:50 +08:00 committed by GitHub
commit 5ef289e581
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 2 deletions

View File

@ -16,8 +16,10 @@ import java.util.Map;
public class DeTaskExecutor { public class DeTaskExecutor {
protected static final String IS_TEMP_TASK = "isTempTask"; protected static final String IS_TEMP_TASK = "isTempTask";
protected static final String IS_RETRY_TASK = "isRetryTask";
private static final String JOB_GROUP = "REPORT_TASK"; private static final String JOB_GROUP = "REPORT_TASK";
private static final String RETRY_JOB_GROUP = "RETRY_REPORT_TASK";
private static final String TEMP_JOB_GROUP = "TEMP_REPORT_TASK"; private static final String TEMP_JOB_GROUP = "TEMP_REPORT_TASK";
@Resource @Resource
@ -47,6 +49,28 @@ public class DeTaskExecutor {
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap); scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap);
} }
public void addRetryTask(Long taskId, Integer retryLimit, Integer retryInterval) {
long saltTime = 3000L;
long interval = retryInterval == null ? 0L : retryInterval;
long intervalMill = interval * 60000L;
long now = System.currentTimeMillis();
long startTime = now - saltTime + intervalMill;
String cron = "0 */" + retryInterval + " * * * ?";
long endTime = (retryLimit - 1) * intervalMill + startTime + saltTime;
String key = taskId.toString();
if (CronUtils.taskExpire(endTime)) {
return;
}
JobKey jobKey = new JobKey(key, RETRY_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, RETRY_JOB_GROUP);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskId", taskId);
jobDataMap.put(IS_RETRY_TASK, true);
Date end = null;
if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap);
}
public boolean fireNow(Long taskId) throws Exception { public boolean fireNow(Long taskId) throws Exception {
String key = taskId.toString(); String key = taskId.toString();
JobKey jobKey = new JobKey(key, JOB_GROUP); JobKey jobKey = new JobKey(key, JOB_GROUP);
@ -74,4 +98,11 @@ public class DeTaskExecutor {
TriggerKey triggerKey = new TriggerKey(key, isTemp ? TEMP_JOB_GROUP : JOB_GROUP); TriggerKey triggerKey = new TriggerKey(key, isTemp ? TEMP_JOB_GROUP : JOB_GROUP);
scheduleManager.removeJob(jobKey, triggerKey); scheduleManager.removeJob(jobKey, triggerKey);
} }
public void removeRetryTask(Long taskId) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, RETRY_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, RETRY_JOB_GROUP);
scheduleManager.removeJob(jobKey, triggerKey);
}
} }

View File

@ -2427,6 +2427,7 @@ export default {
add_task: '添加任务', add_task: '添加任务',
lark_groups: '飞书群', lark_groups: '飞书群',
send_setting: '发送设置', send_setting: '发送设置',
retrying_settings: '发送失败重试设置',
start_time: '开始时间', start_time: '开始时间',
end_time: '结束时间', end_time: '结束时间',
once_a_day: '每天', once_a_day: '每天',

@ -1 +1 @@
Subproject commit 9695ff58484674dc2e1ba81d564224fc12dad9eb Subproject commit b1ca2c316d9d3f81d88c4987d4bad6985374d080

View File

@ -22,7 +22,7 @@ public class ReportCreator implements Serializable {
private Integer rtid; private Integer rtid;
@JsonSerialize(using= ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long rid; private Long rid;
private Integer format; private Integer format;
@ -53,5 +53,11 @@ public class ReportCreator implements Serializable {
private Long endTime; private Long endTime;
private Boolean retryEnable;
private Integer retryLimit;
private Integer retryInterval;
private List<VisualizationReportFilterVO> reportFilter; private List<VisualizationReportFilterVO> reportFilter;
} }

View File

@ -54,4 +54,10 @@ public class ReportInfoVO implements Serializable {
private Long startTime; private Long startTime;
private Long endTime; private Long endTime;
private Boolean retryEnable;
private Integer retryLimit;
private Integer retryInterval;
} }