forked from github/dataease
Merge pull request #9499 from dataease/pr@dev-v2@perf_report_task
perf(X-Pack): 定时报告
This commit is contained in:
commit
8bd8bb4168
@ -34,6 +34,14 @@ public class CronUtils {
|
||||
return date;
|
||||
}
|
||||
|
||||
public static String cron() {
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.add(Calendar.SECOND, 5);
|
||||
return instance.get(Calendar.SECOND) + " " +
|
||||
instance.get(Calendar.MINUTE) + " " +
|
||||
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
|
||||
}
|
||||
|
||||
public static String cron(Integer rateType, String rateVal) {
|
||||
if (rateType == 0) {
|
||||
return rateVal;
|
||||
|
@ -14,6 +14,8 @@ import java.util.Date;
|
||||
@Component
|
||||
public class DeTaskExecutor {
|
||||
|
||||
protected static final String IS_TEMP_TASK = "isTempTask";
|
||||
|
||||
@Resource
|
||||
private ScheduleManager scheduleManager;
|
||||
|
||||
@ -22,6 +24,11 @@ public class DeTaskExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
@XpackInteract(value = "xpackTaskExecutor", replace = true)
|
||||
public boolean executeTemplate(Long taskId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addOrUpdateTask(Long taskId, String cron, Long startTime, Long endTime) {
|
||||
if (CronUtils.taskExpire(endTime)) {
|
||||
return;
|
||||
@ -31,11 +38,29 @@ public class DeTaskExecutor {
|
||||
TriggerKey triggerKey = new TriggerKey(key, key);
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put("taskId", taskId);
|
||||
jobDataMap.put(IS_TEMP_TASK, false);
|
||||
Date end = null;
|
||||
if (ObjectUtils.isNotEmpty(endTime)) end = new Date(endTime);
|
||||
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), end, jobDataMap);
|
||||
}
|
||||
|
||||
public void fireNow(Long taskId) throws Exception{
|
||||
String key = taskId.toString();
|
||||
JobKey jobKey = new JobKey(key, key);
|
||||
scheduleManager.fireNow(jobKey);
|
||||
}
|
||||
|
||||
public void addTempTask(Long taskId, Long startTime) {
|
||||
String key = taskId.toString();
|
||||
JobKey jobKey = new JobKey(key, key);
|
||||
TriggerKey triggerKey = new TriggerKey(key, key);
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put(IS_TEMP_TASK, true);
|
||||
String cron = CronUtils.cron();
|
||||
jobDataMap.put("taskId", taskId);
|
||||
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), null, jobDataMap);
|
||||
}
|
||||
|
||||
public void removeTask(Long taskId) {
|
||||
String key = taskId.toString();
|
||||
JobKey jobKey = new JobKey(key);
|
||||
|
@ -11,14 +11,24 @@ import java.util.Objects;
|
||||
public class DeXpackScheduleJob implements Job {
|
||||
@Resource
|
||||
private DeTaskExecutor deTaskExecutor;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
Trigger trigger = jobExecutionContext.getTrigger();
|
||||
JobKey jobKey = trigger.getJobKey();
|
||||
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
|
||||
Long taskId = jobDataMap.getLong("taskId");
|
||||
if (!deTaskExecutor.execute(taskId)) {
|
||||
boolean isTempTask = jobDataMap.getBoolean("isTempTask");
|
||||
boolean taskLoaded = false;
|
||||
if (isTempTask) {
|
||||
taskLoaded = deTaskExecutor.executeTemplate(taskId);
|
||||
} else {
|
||||
taskLoaded = deTaskExecutor.execute(taskId);
|
||||
}
|
||||
if (!taskLoaded) {
|
||||
Objects.requireNonNull(CommonBeanFactory.getBean(ScheduleManager.class)).removeJob(jobKey, trigger.getKey());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
||||
Subproject commit d8dce708b28bd0d0cbecc5db2c61a0693198b079
|
||||
Subproject commit 1ce831779b69626bdb865b36454b7f91ce17eeb7
|
@ -0,0 +1,28 @@
|
||||
package io.dataease.constant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum ReportLastStatusEnum {
|
||||
EMPTY(0), RUN(1), SUCCESS(2), FAIL(3);
|
||||
|
||||
private Integer flag;
|
||||
|
||||
public Integer getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(Integer flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
ReportLastStatusEnum() {
|
||||
}
|
||||
|
||||
ReportLastStatusEnum(Integer flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static ReportLastStatusEnum fromValue(Integer flag) {
|
||||
return Arrays.stream(values()).filter(v -> v.flag.equals(flag)).findFirst().get();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package io.dataease.constant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum ReportTaskEnum {
|
||||
|
||||
WAIT(0), SEND(1), STOP(2), FINISH(3);
|
||||
|
||||
private Integer flag;
|
||||
|
||||
public Integer getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(Integer flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
ReportTaskEnum(Integer flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
ReportTaskEnum() {
|
||||
}
|
||||
|
||||
public static ReportTaskEnum fromValue(Integer flag) {
|
||||
return Arrays.stream(values()).filter(v -> v.flag.equals(flag)).findFirst().get();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user