perf(X-Pack): 定时报告

This commit is contained in:
fit2cloud-chenyw 2024-05-08 17:56:13 +08:00
parent 908d429772
commit 526bf6c5cb
4 changed files with 13 additions and 23 deletions

View File

@ -34,7 +34,7 @@ public class CronUtils {
return date; return date;
} }
public static String cron() { public static String tempCron() {
Calendar instance = Calendar.getInstance(); Calendar instance = Calendar.getInstance();
instance.add(Calendar.SECOND, 5); instance.add(Calendar.SECOND, 5);
return instance.get(Calendar.SECOND) + " " + return instance.get(Calendar.SECOND) + " " +

View File

@ -10,8 +10,9 @@ import org.quartz.TriggerKey;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
import java.util.Map;
@Component @Component("deTaskExecutor")
public class DeTaskExecutor { public class DeTaskExecutor {
protected static final String IS_TEMP_TASK = "isTempTask"; protected static final String IS_TEMP_TASK = "isTempTask";
@ -20,12 +21,7 @@ public class DeTaskExecutor {
private ScheduleManager scheduleManager; private ScheduleManager scheduleManager;
@XpackInteract(value = "xpackTaskExecutor", replace = true) @XpackInteract(value = "xpackTaskExecutor", replace = true)
public boolean execute(Long taskId) { public boolean execute(Map<String, Object> taskData) {
return false;
}
@XpackInteract(value = "xpackTaskExecutor", replace = true)
public boolean executeTemplate(Long taskId) {
return false; return false;
} }
@ -44,7 +40,7 @@ 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 fireNow(Long taskId) throws Exception{ public void fireNow(Long taskId) throws Exception {
String key = taskId.toString(); String key = taskId.toString();
JobKey jobKey = new JobKey(key, key); JobKey jobKey = new JobKey(key, key);
scheduleManager.fireNow(jobKey); scheduleManager.fireNow(jobKey);
@ -56,7 +52,7 @@ public class DeTaskExecutor {
TriggerKey triggerKey = new TriggerKey(key, key); TriggerKey triggerKey = new TriggerKey(key, key);
JobDataMap jobDataMap = new JobDataMap(); JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(IS_TEMP_TASK, true); jobDataMap.put(IS_TEMP_TASK, true);
String cron = CronUtils.cron(); String cron = CronUtils.tempCron();
jobDataMap.put("taskId", taskId); jobDataMap.put("taskId", taskId);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), null, jobDataMap); scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, DeXpackScheduleJob.class, cron, new Date(startTime), null, jobDataMap);
} }

View File

@ -1,5 +1,6 @@
package io.dataease.job.schedule; package io.dataease.job.schedule;
import io.dataease.license.utils.LicenseUtil;
import io.dataease.utils.CommonBeanFactory; import io.dataease.utils.CommonBeanFactory;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.quartz.*; import org.quartz.*;
@ -9,26 +10,19 @@ import java.util.Objects;
@Component @Component
public class DeXpackScheduleJob implements Job { public class DeXpackScheduleJob implements Job {
@Resource
private DeTaskExecutor deTaskExecutor;
@Override @Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
Trigger trigger = jobExecutionContext.getTrigger(); Trigger trigger = jobExecutionContext.getTrigger();
JobKey jobKey = trigger.getJobKey(); JobKey jobKey = trigger.getJobKey();
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
Long taskId = jobDataMap.getLong("taskId"); DeTaskExecutor deTaskExecutor = CommonBeanFactory.getBean(DeTaskExecutor.class);
boolean isTempTask = jobDataMap.getBoolean("isTempTask"); assert deTaskExecutor != null;
boolean taskLoaded = false; LicenseUtil.validate();
if (isTempTask) { boolean taskLoaded = deTaskExecutor.execute(jobDataMap);
taskLoaded = deTaskExecutor.executeTemplate(taskId);
} else {
taskLoaded = deTaskExecutor.execute(taskId);
}
if (!taskLoaded) { if (!taskLoaded) {
Objects.requireNonNull(CommonBeanFactory.getBean(ScheduleManager.class)).removeJob(jobKey, trigger.getKey()); Objects.requireNonNull(CommonBeanFactory.getBean(ScheduleManager.class)).removeJob(jobKey, trigger.getKey());
} }
} }
} }

@ -1 +1 @@
Subproject commit 1ce831779b69626bdb865b36454b7f91ce17eeb7 Subproject commit b61bcfc7325c5d9a1f30564d27dab3f098ac228c