forked from github/dataease
feat: 更新任务立即执行时,
This commit is contained in:
parent
edfb017066
commit
f99865cf8d
@ -268,18 +268,18 @@ public class DataSetTableService {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
|
||||
if (StringUtils.isEmpty(datasetTable.getSyncStatus()) || datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Underway.name())) {
|
||||
map.put("status", "warnning");
|
||||
map.put("msg", Translator.get("i18n_processing_data"));
|
||||
dataSetPreviewPage.setTotal(0);
|
||||
}else if (datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Error.name())) {
|
||||
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId());
|
||||
if (CollectionUtils.isEmpty(datasetTableTaskLogs)) {
|
||||
map.put("status", "warnning");
|
||||
map.put("msg", Translator.get("i18n_processing_data"));
|
||||
dataSetPreviewPage.setTotal(0);
|
||||
}else if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Underway.name())) {
|
||||
map.put("status", "warnning");
|
||||
map.put("msg", Translator.get("i18n_processing_data"));
|
||||
dataSetPreviewPage.setTotal(0);
|
||||
}else if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Error.name())) {
|
||||
map.put("status", "error");
|
||||
if(CollectionUtils.isNotEmpty(datasetTableTaskLogs)){
|
||||
map.put("msg", "Failed to extract data: " + datasetTableTaskLogs.get(0).getInfo());
|
||||
}else {
|
||||
map.put("msg", "Failed to extract data.");
|
||||
}
|
||||
dataSetPreviewPage.setTotal(0);
|
||||
}else {
|
||||
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");
|
||||
|
@ -4,6 +4,7 @@ import io.dataease.base.domain.DatasetTableTaskLog;
|
||||
import io.dataease.base.domain.DatasetTableTaskLogExample;
|
||||
import io.dataease.base.mapper.DatasetTableTaskLogMapper;
|
||||
import io.dataease.base.mapper.ext.ExtDataSetTaskMapper;
|
||||
import io.dataease.commons.constants.JobStatus;
|
||||
import io.dataease.dto.dataset.DataSetTaskLogDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -55,4 +56,19 @@ public class DataSetTableTaskLogService {
|
||||
criteria.andTableIdEqualTo(datasetId);
|
||||
return datasetTableTaskLogMapper.selectByExampleWithBLOBs(datasetTableTaskLogExample);
|
||||
}
|
||||
|
||||
public List<DatasetTableTaskLog> select(DatasetTableTaskLog datasetTableTaskLog){
|
||||
DatasetTableTaskLogExample example = new DatasetTableTaskLogExample();
|
||||
DatasetTableTaskLogExample.Criteria criteria = example.createCriteria();
|
||||
if(StringUtils.isNotEmpty(datasetTableTaskLog.getStatus())){
|
||||
criteria.andStatusEqualTo(datasetTableTaskLog.getStatus());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(datasetTableTaskLog.getTableId())){
|
||||
criteria.andTableIdEqualTo(datasetTableTaskLog.getTableId());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(datasetTableTaskLog.getTaskId())){
|
||||
criteria.andTaskIdEqualTo(datasetTableTaskLog.getTaskId());
|
||||
}
|
||||
return datasetTableTaskLogMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package io.dataease.service.dataset;
|
||||
|
||||
import io.dataease.base.domain.DatasetTableTask;
|
||||
import io.dataease.base.domain.DatasetTableTaskExample;
|
||||
import io.dataease.base.domain.DatasetTableTaskLog;
|
||||
import io.dataease.base.mapper.DatasetTableTaskMapper;
|
||||
import io.dataease.commons.constants.JobStatus;
|
||||
import io.dataease.commons.constants.ScheduleType;
|
||||
import io.dataease.controller.request.dataset.DataSetTaskRequest;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.ScheduleService;
|
||||
@ -33,10 +36,12 @@ public class DataSetTableTaskService {
|
||||
@Resource
|
||||
@Lazy
|
||||
private DataSetTableService dataSetTableService;
|
||||
|
||||
@Resource
|
||||
private ExtractDataService extractDataService;
|
||||
public DatasetTableTask save(DataSetTaskRequest dataSetTaskRequest) throws Exception {
|
||||
dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig());
|
||||
DatasetTableTask datasetTableTask = dataSetTaskRequest.getDatasetTableTask();
|
||||
dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig());
|
||||
|
||||
// check
|
||||
if (StringUtils.isNotEmpty(datasetTableTask.getCron())) {
|
||||
if (!CronExpression.isValidExpression(datasetTableTask.getCron())) {
|
||||
@ -54,6 +59,20 @@ public class DataSetTableTaskService {
|
||||
if (StringUtils.isEmpty(datasetTableTask.getId())) {
|
||||
datasetTableTask.setId(UUID.randomUUID().toString());
|
||||
datasetTableTask.setCreateTime(System.currentTimeMillis());
|
||||
// SIMPLE 类型,提前占位
|
||||
if(datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())){
|
||||
if(extractDataService.updateSyncStatus(dataSetTableService.get(datasetTableTask.getTableId()))){
|
||||
throw new Exception(Translator.get("i18n_sync_job_exists"));
|
||||
}else {
|
||||
//write log
|
||||
DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog();
|
||||
datasetTableTaskLog.setTableId(datasetTableTask.getTableId());
|
||||
datasetTableTaskLog.setTaskId(datasetTableTask.getId());
|
||||
datasetTableTaskLog.setStatus(JobStatus.Underway.name());
|
||||
datasetTableTaskLog.setStartTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
}
|
||||
}
|
||||
datasetTableTaskMapper.insert(datasetTableTask);
|
||||
} else {
|
||||
datasetTableTaskMapper.updateByPrimaryKeySelective(datasetTableTask);
|
||||
|
@ -3,6 +3,7 @@ package io.dataease.service.dataset;
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.DatasetTableMapper;
|
||||
import io.dataease.base.mapper.DatasetTableTaskMapper;
|
||||
import io.dataease.base.mapper.DatasourceMapper;
|
||||
import io.dataease.commons.constants.JobStatus;
|
||||
import io.dataease.commons.constants.ScheduleType;
|
||||
@ -90,13 +91,17 @@ public class ExtractDataService {
|
||||
@Resource
|
||||
private DataSetTableFieldsService dataSetTableFieldsService;
|
||||
@Resource
|
||||
@Lazy
|
||||
private DataSetTableTaskLogService dataSetTableTaskLogService;
|
||||
@Resource
|
||||
@Lazy
|
||||
private DataSetTableTaskService dataSetTableTaskService;
|
||||
@Resource
|
||||
private DatasourceMapper datasourceMapper;
|
||||
@Resource
|
||||
private DatasetTableMapper datasetTableMapper;
|
||||
@Resource
|
||||
private DatasetTableTaskMapper datasetTableTaskMapper;
|
||||
|
||||
private static String lastUpdateTime = "${__last_update_time__}";
|
||||
private static String currentUpdateTime = "${__current_update_time__}";
|
||||
@ -176,7 +181,7 @@ public class ExtractDataService {
|
||||
}
|
||||
|
||||
|
||||
private synchronized boolean updateSyncStatus(DatasetTable datasetTable ){
|
||||
public synchronized boolean updateSyncStatus(DatasetTable datasetTable ){
|
||||
datasetTable.setSyncStatus(JobStatus.Underway.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusEqualTo(JobStatus.Completed.name());
|
||||
@ -186,7 +191,9 @@ public class ExtractDataService {
|
||||
|
||||
public void extractData(String datasetTableId, String taskId, String type, JobExecutionContext context) {
|
||||
DatasetTable datasetTable = dataSetTableService.get(datasetTableId);
|
||||
if(updateSyncStatus(datasetTable)){
|
||||
DatasetTableTask datasetTableTask = datasetTableTaskMapper.selectByPrimaryKey(taskId);
|
||||
boolean isSIMPLEJob = (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString()));
|
||||
if(updateSyncStatus(datasetTable) && !isSIMPLEJob){
|
||||
LogUtil.info("Skip synchronization task for table : " + datasetTableId);
|
||||
return;
|
||||
}
|
||||
@ -276,7 +283,6 @@ public class ExtractDataService {
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
} finally {
|
||||
DatasetTableTask datasetTableTask = dataSetTableTaskService.get(taskId);
|
||||
if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString());
|
||||
dataSetTableTaskService.update(datasetTableTask);
|
||||
@ -292,9 +298,11 @@ public class ExtractDataService {
|
||||
datasetTableTaskLog.setTableId(datasetTableId);
|
||||
datasetTableTaskLog.setTaskId(taskId);
|
||||
datasetTableTaskLog.setStatus(JobStatus.Underway.name());
|
||||
if(CollectionUtils.isEmpty(dataSetTableTaskLogService.select(datasetTableTaskLog))){
|
||||
datasetTableTaskLog.setStartTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
}
|
||||
}
|
||||
|
||||
private void extractData(DatasetTable datasetTable, String extractType) throws Exception {
|
||||
|
||||
|
@ -242,4 +242,4 @@ i18n_cron_time_error=Start time can't greater then end time
|
||||
i18n_auth_source_be_canceled=This Auth Resource Already Be Canceled
|
||||
i18n_username_exists=ID is already exists
|
||||
i18n_ds_name_exists=Datasource name exists
|
||||
|
||||
i18n_sync_job_exists=There is already a synchronization task running, please try again later
|
||||
|
@ -244,3 +244,4 @@ i18n_cron_time_error=开始时间不能大于结束时间
|
||||
i18n_auth_source_be_canceled=当前资源授权权限已经被取消
|
||||
i18n_username_exists=用户ID已存在
|
||||
i18n_ds_name_exists=数据源名称已存在
|
||||
i18n_sync_job_exists=已经有同步任务在运行,稍后重试
|
||||
|
@ -244,3 +244,4 @@ i18n_cron_time_error=開始時間不能大於結束時間
|
||||
i18n_auth_source_be_canceled=當前資源授權權限已經被取消
|
||||
i18n_username_exists=用戶ID已存在
|
||||
i18n_ds_name_exists=數據源名稱已存在
|
||||
i18n_sync_job_exists=已經有同步任務在運行,稍後重試
|
||||
|
@ -732,13 +732,13 @@ export default {
|
||||
error: 'Error',
|
||||
completed: 'Completed',
|
||||
underway: 'underway',
|
||||
task_update: 'Regular update',
|
||||
task_update: 'Update Setting',
|
||||
update_type: 'Update Type',
|
||||
all_scope: 'Full update',
|
||||
add_scope: 'Incremental update',
|
||||
select_data_time: 'Select date time',
|
||||
execute_rate: 'Execution frequency',
|
||||
execute_once: 'Only once',
|
||||
execute_once: 'Execution Now',
|
||||
cron_config: 'Expression setting',
|
||||
no_limit: 'No limit',
|
||||
set_end_time: 'Set the end time',
|
||||
|
@ -732,13 +732,13 @@ export default {
|
||||
error: '錯誤',
|
||||
completed: '完成',
|
||||
underway: '執行中',
|
||||
task_update: '定時更新',
|
||||
task_update: '更新設置',
|
||||
update_type: '更新方式',
|
||||
all_scope: '全量更新',
|
||||
add_scope: '增量更新',
|
||||
select_data_time: '選擇日期時間',
|
||||
execute_rate: '執行頻率',
|
||||
execute_once: '只執行一次',
|
||||
execute_once: '立即執行',
|
||||
cron_config: '表達時設定',
|
||||
no_limit: '無限制',
|
||||
set_end_time: '設定結束時間',
|
||||
|
@ -732,13 +732,13 @@ export default {
|
||||
error: '错误',
|
||||
completed: '完成',
|
||||
underway: '执行中',
|
||||
task_update: '定时更新',
|
||||
task_update: '更新设置',
|
||||
update_type: '更新方式',
|
||||
all_scope: '全量更新',
|
||||
add_scope: '增量更新',
|
||||
select_data_time: '选择日期时间',
|
||||
execute_rate: '执行频率',
|
||||
execute_once: '只执行一次',
|
||||
execute_once: '立即执行',
|
||||
cron_config: '表达式设定',
|
||||
no_limit: '无限制',
|
||||
set_end_time: '设定结束时间',
|
||||
|
@ -116,14 +116,6 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('dataset.start_time')" prop="startTime">
|
||||
<el-date-picker
|
||||
v-model="taskForm.startTime"
|
||||
type="datetime"
|
||||
:placeholder="$t('dataset.select_data_time')"
|
||||
size="mini"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('dataset.execute_rate')" prop="rate">
|
||||
<el-select v-model="taskForm.rate" size="mini" @change="onRateChange">
|
||||
<el-option
|
||||
@ -136,13 +128,22 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="taskForm.rate === 'CRON'" label="">
|
||||
<el-popover v-model="cronEdit">
|
||||
<cron v-model="taskForm.cron" @close="cronEdit = false" />
|
||||
<el-input slot="reference" v-model="taskForm.cron" size="mini" style="width: 50%" @click="cronEdit = true" />
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('dataset.end_time')" prop="end">
|
||||
<el-form-item v-if="taskForm.rate === 'CRON'" :label="$t('dataset.start_time')" prop="startTime">
|
||||
<el-date-picker
|
||||
v-model="taskForm.startTime"
|
||||
type="datetime"
|
||||
:placeholder="$t('dataset.select_data_time')"
|
||||
size="mini"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="taskForm.rate === 'CRON'" :label="$t('dataset.end_time')" prop="end">
|
||||
<el-select v-model="taskForm.end" size="mini">
|
||||
<el-option
|
||||
:label="$t('dataset.no_limit')"
|
||||
|
Loading…
Reference in New Issue
Block a user