Merge pull request #11507 from dataease/pr@dev-v2@perf_threshold_task

perf(X-Pack): 阈值告警定时任务
This commit is contained in:
fit2cloud-chenyw
2024-08-12 18:09:01 +08:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@@ -22,6 +22,8 @@ public class DeTaskExecutor {
private static final String RETRY_JOB_GROUP = "RETRY_REPORT_TASK";
private static final String TEMP_JOB_GROUP = "TEMP_REPORT_TASK";
private static final String THRESHOLD_JOB_GROUP = "THRESHOLD_TASK";
@Resource
private ScheduleManager scheduleManager;
@@ -34,6 +36,21 @@ public class DeTaskExecutor {
public void init() {
}
public void addThresholdTask(Long taskId, String cron, Long startTime, Long endTime) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, THRESHOLD_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, THRESHOLD_JOB_GROUP);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskId", taskId);
jobDataMap.put("threshold", taskId);
Date end = null;
if (CronUtils.taskExpire(endTime)) {
return;
}
if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap);
}
public void addOrUpdateTask(Long taskId, String cron, Long startTime, Long endTime) {
if (CronUtils.taskExpire(endTime)) {
return;
@@ -106,6 +123,13 @@ public class DeTaskExecutor {
scheduleManager.removeJob(jobKey, triggerKey);
}
public void removeThresholdTask(Long taskId) {
String key = taskId.toString();
JobKey jobKey = new JobKey(key, THRESHOLD_JOB_GROUP);
TriggerKey triggerKey = new TriggerKey(key, THRESHOLD_JOB_GROUP);
scheduleManager.removeJob(jobKey, triggerKey);
}
public void clearRetryTask() throws Exception {
scheduleManager.clearByGroup(RETRY_JOB_GROUP);
}