diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index 3e07e263b4..8ef8b3c598 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -33,14 +33,20 @@ import io.dataease.datasource.request.DatasourceRequest; import io.dataease.engine.constant.SQLConstants; import io.dataease.exception.DEException; import io.dataease.i18n.Translator; +import io.dataease.job.sechedule.CheckDsStatusJob; +import io.dataease.job.sechedule.ScheduleManager; import io.dataease.license.config.XpackInteract; import io.dataease.model.BusiNodeRequest; import io.dataease.model.BusiNodeVO; +import io.dataease.system.dao.auto.entity.CoreSysSetting; import io.dataease.system.manage.CoreUserManage; import io.dataease.utils.*; import jakarta.annotation.Resource; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.quartz.JobDataMap; +import org.quartz.JobKey; +import org.quartz.TriggerKey; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestBody; @@ -85,7 +91,8 @@ public class DatasourceServer implements DatasourceApi { @Resource private DatasetDataManage datasetDataManage; - + @Resource + private ScheduleManager scheduleManager; @Resource private CoreUserManage coreUserManage; @@ -605,6 +612,31 @@ public class DatasourceServer implements DatasourceApi { return validate(coreDatasource); } + public void addJob(List sysSettings) { + String type = "minute"; + String interval = "30"; + for (CoreSysSetting sysSetting : sysSettings) { + if (sysSetting.getPkey().equalsIgnoreCase("basic.dsExecuteTime")) { + type = sysSetting.getPval(); + } + if (sysSetting.getPkey().equalsIgnoreCase("basic.dsIntervalTime")) { + interval = sysSetting.getPval(); + } + } + String cron = ""; + switch (type) { + case "hour": + cron = "0 0 0/hour * * ? *".replace("hour", interval.toString()); + break; + default: + cron = "0 0/minute * * * ? *".replace("minute", interval.toString()); + } + scheduleManager.addOrUpdateCronJob(new JobKey("Datasource", "check_status"), + new TriggerKey("Datasource", "check_status"), + CheckDsStatusJob.class, + cron, new Date(System.currentTimeMillis()), null, new JobDataMap()); + } + private DatasourceDTO validate(CoreDatasource coreDatasource) { checkDatasourceStatus(coreDatasource); DatasourceDTO datasourceDTO = new DatasourceDTO(); diff --git a/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java b/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java index 4acfab638c..cb42755571 100644 --- a/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java +++ b/core/core-backend/src/main/java/io/dataease/job/sechedule/Schedular.java @@ -18,9 +18,4 @@ public class Schedular { datasourceServer.updateStopJobStatus(); } - @QuartzScheduled(cron = "0 0/30 * * * ?") - public void updateDatasourceStatus() { - datasourceServer.updateDatasourceStatus(); - } - } diff --git a/core/core-backend/src/main/java/io/dataease/listener/DataSourceInitStartListener.java b/core/core-backend/src/main/java/io/dataease/listener/DataSourceInitStartListener.java index 72dbae8e67..ec8324d30d 100644 --- a/core/core-backend/src/main/java/io/dataease/listener/DataSourceInitStartListener.java +++ b/core/core-backend/src/main/java/io/dataease/listener/DataSourceInitStartListener.java @@ -6,6 +6,8 @@ import io.dataease.datasource.provider.CalciteProvider; import io.dataease.datasource.server.DatasourceServer; import io.dataease.datasource.server.DatasourceTaskServer; import io.dataease.datasource.server.EngineServer; +import io.dataease.system.dao.auto.entity.CoreSysSetting; +import io.dataease.system.manage.SysParameterManage; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.boot.context.event.ApplicationReadyEvent; @@ -29,6 +31,8 @@ public class DataSourceInitStartListener implements ApplicationListener coreSysSettings = sysParameterManage.groupList("basic."); + datasourceServer.addJob(coreSysSettings); + }catch (Exception e){ + e.printStackTrace(); + } + } diff --git a/core/core-backend/src/main/java/io/dataease/system/manage/SysParameterManage.java b/core/core-backend/src/main/java/io/dataease/system/manage/SysParameterManage.java index 4f9d477557..063757433e 100644 --- a/core/core-backend/src/main/java/io/dataease/system/manage/SysParameterManage.java +++ b/core/core-backend/src/main/java/io/dataease/system/manage/SysParameterManage.java @@ -2,6 +2,7 @@ package io.dataease.system.manage; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.dataease.api.system.vo.SettingItemVO; +import io.dataease.datasource.server.DatasourceServer; import io.dataease.license.config.XpackInteract; import io.dataease.system.dao.auto.entity.CoreSysSetting; import io.dataease.system.dao.auto.mapper.CoreSysSettingMapper; @@ -31,6 +32,8 @@ public class SysParameterManage { @Resource private ExtCoreSysSettingMapper extCoreSysSettingMapper; + @Resource + private DatasourceServer datasourceServer; public String singleVal(String key) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -100,6 +103,7 @@ public class SysParameterManage { return sysSetting; }).collect(Collectors.toList()); extCoreSysSettingMapper.saveBatch(sysSettings); + datasourceServer.addJob(sysSettings); }