forked from github/dataease
Merge pull request #6933 from dataease/pr@dev-v2@fixDatasource
feat: 读取数据源更新频率配置
This commit is contained in:
commit
0e4667e5c9
@ -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<CoreSysSetting> 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();
|
||||
|
@ -18,9 +18,4 @@ public class Schedular {
|
||||
datasourceServer.updateStopJobStatus();
|
||||
}
|
||||
|
||||
@QuartzScheduled(cron = "0 0/30 * * * ?")
|
||||
public void updateDatasourceStatus() {
|
||||
datasourceServer.updateDatasourceStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Applicat
|
||||
private CalciteProvider calciteProvider;
|
||||
@Resource
|
||||
private EngineServer engineServer;
|
||||
@Resource
|
||||
private SysParameterManage sysParameterManage;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
@ -62,6 +66,14 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
List<CoreSysSetting> coreSysSettings = sysParameterManage.groupList("basic.");
|
||||
datasourceServer.addJob(coreSysSettings);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<CoreSysSetting> queryWrapper = new QueryWrapper<>();
|
||||
@ -100,6 +103,7 @@ public class SysParameterManage {
|
||||
return sysSetting;
|
||||
}).collect(Collectors.toList());
|
||||
extCoreSysSettingMapper.saveBatch(sysSettings);
|
||||
datasourceServer.addJob(sysSettings);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user