feat: 更新任务立即执行时,

This commit is contained in:
taojinlong 2021-05-28 16:37:37 +08:00
parent edfb017066
commit f99865cf8d
11 changed files with 77 additions and 31 deletions

View File

@ -268,18 +268,18 @@ public class DataSetTableService {
e.printStackTrace(); e.printStackTrace();
} }
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) { } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId()); if (StringUtils.isEmpty(datasetTable.getSyncStatus()) || datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Underway.name())) {
if (CollectionUtils.isEmpty(datasetTableTaskLogs)) {
map.put("status", "warnning"); map.put("status", "warnning");
map.put("msg", Translator.get("i18n_processing_data")); map.put("msg", Translator.get("i18n_processing_data"));
dataSetPreviewPage.setTotal(0); dataSetPreviewPage.setTotal(0);
}else if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Underway.name())) { }else if (datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Error.name())) {
map.put("status", "warnning"); List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId());
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"); map.put("status", "error");
map.put("msg", "Failed to extract data: " + datasetTableTaskLogs.get(0).getInfo()); 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); dataSetPreviewPage.setTotal(0);
}else { }else {
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource"); Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");

View File

@ -4,6 +4,7 @@ import io.dataease.base.domain.DatasetTableTaskLog;
import io.dataease.base.domain.DatasetTableTaskLogExample; import io.dataease.base.domain.DatasetTableTaskLogExample;
import io.dataease.base.mapper.DatasetTableTaskLogMapper; import io.dataease.base.mapper.DatasetTableTaskLogMapper;
import io.dataease.base.mapper.ext.ExtDataSetTaskMapper; import io.dataease.base.mapper.ext.ExtDataSetTaskMapper;
import io.dataease.commons.constants.JobStatus;
import io.dataease.dto.dataset.DataSetTaskLogDTO; import io.dataease.dto.dataset.DataSetTaskLogDTO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -55,4 +56,19 @@ public class DataSetTableTaskLogService {
criteria.andTableIdEqualTo(datasetId); criteria.andTableIdEqualTo(datasetId);
return datasetTableTaskLogMapper.selectByExampleWithBLOBs(datasetTableTaskLogExample); 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);
}
} }

View File

@ -2,7 +2,10 @@ package io.dataease.service.dataset;
import io.dataease.base.domain.DatasetTableTask; import io.dataease.base.domain.DatasetTableTask;
import io.dataease.base.domain.DatasetTableTaskExample; import io.dataease.base.domain.DatasetTableTaskExample;
import io.dataease.base.domain.DatasetTableTaskLog;
import io.dataease.base.mapper.DatasetTableTaskMapper; 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.controller.request.dataset.DataSetTaskRequest;
import io.dataease.i18n.Translator; import io.dataease.i18n.Translator;
import io.dataease.service.ScheduleService; import io.dataease.service.ScheduleService;
@ -33,10 +36,12 @@ public class DataSetTableTaskService {
@Resource @Resource
@Lazy @Lazy
private DataSetTableService dataSetTableService; private DataSetTableService dataSetTableService;
@Resource
private ExtractDataService extractDataService;
public DatasetTableTask save(DataSetTaskRequest dataSetTaskRequest) throws Exception { public DatasetTableTask save(DataSetTaskRequest dataSetTaskRequest) throws Exception {
dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig());
DatasetTableTask datasetTableTask = dataSetTaskRequest.getDatasetTableTask(); DatasetTableTask datasetTableTask = dataSetTaskRequest.getDatasetTableTask();
dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig());
// check // check
if (StringUtils.isNotEmpty(datasetTableTask.getCron())) { if (StringUtils.isNotEmpty(datasetTableTask.getCron())) {
if (!CronExpression.isValidExpression(datasetTableTask.getCron())) { if (!CronExpression.isValidExpression(datasetTableTask.getCron())) {
@ -54,6 +59,20 @@ public class DataSetTableTaskService {
if (StringUtils.isEmpty(datasetTableTask.getId())) { if (StringUtils.isEmpty(datasetTableTask.getId())) {
datasetTableTask.setId(UUID.randomUUID().toString()); datasetTableTask.setId(UUID.randomUUID().toString());
datasetTableTask.setCreateTime(System.currentTimeMillis()); 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); datasetTableTaskMapper.insert(datasetTableTask);
} else { } else {
datasetTableTaskMapper.updateByPrimaryKeySelective(datasetTableTask); datasetTableTaskMapper.updateByPrimaryKeySelective(datasetTableTask);

View File

@ -3,6 +3,7 @@ package io.dataease.service.dataset;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.dataease.base.domain.*; import io.dataease.base.domain.*;
import io.dataease.base.mapper.DatasetTableMapper; import io.dataease.base.mapper.DatasetTableMapper;
import io.dataease.base.mapper.DatasetTableTaskMapper;
import io.dataease.base.mapper.DatasourceMapper; import io.dataease.base.mapper.DatasourceMapper;
import io.dataease.commons.constants.JobStatus; import io.dataease.commons.constants.JobStatus;
import io.dataease.commons.constants.ScheduleType; import io.dataease.commons.constants.ScheduleType;
@ -90,13 +91,17 @@ public class ExtractDataService {
@Resource @Resource
private DataSetTableFieldsService dataSetTableFieldsService; private DataSetTableFieldsService dataSetTableFieldsService;
@Resource @Resource
@Lazy
private DataSetTableTaskLogService dataSetTableTaskLogService; private DataSetTableTaskLogService dataSetTableTaskLogService;
@Resource @Resource
@Lazy
private DataSetTableTaskService dataSetTableTaskService; private DataSetTableTaskService dataSetTableTaskService;
@Resource @Resource
private DatasourceMapper datasourceMapper; private DatasourceMapper datasourceMapper;
@Resource @Resource
private DatasetTableMapper datasetTableMapper; private DatasetTableMapper datasetTableMapper;
@Resource
private DatasetTableTaskMapper datasetTableTaskMapper;
private static String lastUpdateTime = "${__last_update_time__}"; private static String lastUpdateTime = "${__last_update_time__}";
private static String currentUpdateTime = "${__current_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()); datasetTable.setSyncStatus(JobStatus.Underway.name());
DatasetTableExample example = new DatasetTableExample(); DatasetTableExample example = new DatasetTableExample();
example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusEqualTo(JobStatus.Completed.name()); 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) { public void extractData(String datasetTableId, String taskId, String type, JobExecutionContext context) {
DatasetTable datasetTable = dataSetTableService.get(datasetTableId); 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); LogUtil.info("Skip synchronization task for table : " + datasetTableId);
return; return;
} }
@ -276,7 +283,6 @@ public class ExtractDataService {
datasetTableTaskLog.setEndTime(System.currentTimeMillis()); datasetTableTaskLog.setEndTime(System.currentTimeMillis());
dataSetTableTaskLogService.save(datasetTableTaskLog); dataSetTableTaskLogService.save(datasetTableTaskLog);
} finally { } finally {
DatasetTableTask datasetTableTask = dataSetTableTaskService.get(taskId);
if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) { if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString()); datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString());
dataSetTableTaskService.update(datasetTableTask); dataSetTableTaskService.update(datasetTableTask);
@ -292,8 +298,10 @@ public class ExtractDataService {
datasetTableTaskLog.setTableId(datasetTableId); datasetTableTaskLog.setTableId(datasetTableId);
datasetTableTaskLog.setTaskId(taskId); datasetTableTaskLog.setTaskId(taskId);
datasetTableTaskLog.setStatus(JobStatus.Underway.name()); datasetTableTaskLog.setStatus(JobStatus.Underway.name());
datasetTableTaskLog.setStartTime(System.currentTimeMillis()); if(CollectionUtils.isEmpty(dataSetTableTaskLogService.select(datasetTableTaskLog))){
dataSetTableTaskLogService.save(datasetTableTaskLog); datasetTableTaskLog.setStartTime(System.currentTimeMillis());
dataSetTableTaskLogService.save(datasetTableTaskLog);
}
} }
private void extractData(DatasetTable datasetTable, String extractType) throws Exception { private void extractData(DatasetTable datasetTable, String extractType) throws Exception {

View File

@ -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_auth_source_be_canceled=This Auth Resource Already Be Canceled
i18n_username_exists=ID is already exists i18n_username_exists=ID is already exists
i18n_ds_name_exists=Datasource name exists i18n_ds_name_exists=Datasource name exists
i18n_sync_job_exists=There is already a synchronization task running, please try again later

View File

@ -244,3 +244,4 @@ i18n_cron_time_error=开始时间不能大于结束时间
i18n_auth_source_be_canceled=当前资源授权权限已经被取消 i18n_auth_source_be_canceled=当前资源授权权限已经被取消
i18n_username_exists=用户ID已存在 i18n_username_exists=用户ID已存在
i18n_ds_name_exists=数据源名称已存在 i18n_ds_name_exists=数据源名称已存在
i18n_sync_job_exists=已经有同步任务在运行,稍后重试

View File

@ -244,3 +244,4 @@ i18n_cron_time_error=開始時間不能大於結束時間
i18n_auth_source_be_canceled=當前資源授權權限已經被取消 i18n_auth_source_be_canceled=當前資源授權權限已經被取消
i18n_username_exists=用戶ID已存在 i18n_username_exists=用戶ID已存在
i18n_ds_name_exists=數據源名稱已存在 i18n_ds_name_exists=數據源名稱已存在
i18n_sync_job_exists=已經有同步任務在運行,稍後重試

View File

@ -732,13 +732,13 @@ export default {
error: 'Error', error: 'Error',
completed: 'Completed', completed: 'Completed',
underway: 'underway', underway: 'underway',
task_update: 'Regular update', task_update: 'Update Setting',
update_type: 'Update Type', update_type: 'Update Type',
all_scope: 'Full update', all_scope: 'Full update',
add_scope: 'Incremental update', add_scope: 'Incremental update',
select_data_time: 'Select date time', select_data_time: 'Select date time',
execute_rate: 'Execution frequency', execute_rate: 'Execution frequency',
execute_once: 'Only once', execute_once: 'Execution Now',
cron_config: 'Expression setting', cron_config: 'Expression setting',
no_limit: 'No limit', no_limit: 'No limit',
set_end_time: 'Set the end time', set_end_time: 'Set the end time',

View File

@ -732,13 +732,13 @@ export default {
error: '錯誤', error: '錯誤',
completed: '完成', completed: '完成',
underway: '執行中', underway: '執行中',
task_update: '定時更新', task_update: '更新設置',
update_type: '更新方式', update_type: '更新方式',
all_scope: '全量更新', all_scope: '全量更新',
add_scope: '增量更新', add_scope: '增量更新',
select_data_time: '選擇日期時間', select_data_time: '選擇日期時間',
execute_rate: '執行頻率', execute_rate: '執行頻率',
execute_once: '只執行一次', execute_once: '立即執行',
cron_config: '表達時設定', cron_config: '表達時設定',
no_limit: '無限制', no_limit: '無限制',
set_end_time: '設定結束時間', set_end_time: '設定結束時間',

View File

@ -732,13 +732,13 @@ export default {
error: '错误', error: '错误',
completed: '完成', completed: '完成',
underway: '执行中', underway: '执行中',
task_update: '定时更新', task_update: '更新设置',
update_type: '更新方式', update_type: '更新方式',
all_scope: '全量更新', all_scope: '全量更新',
add_scope: '增量更新', add_scope: '增量更新',
select_data_time: '选择日期时间', select_data_time: '选择日期时间',
execute_rate: '执行频率', execute_rate: '执行频率',
execute_once: '只执行一次', execute_once: '立即执行',
cron_config: '表达式设定', cron_config: '表达式设定',
no_limit: '无限制', no_limit: '无限制',
set_end_time: '设定结束时间', set_end_time: '设定结束时间',

View File

@ -116,14 +116,6 @@
/> />
</el-select> </el-select>
</el-form-item> </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-form-item :label="$t('dataset.execute_rate')" prop="rate">
<el-select v-model="taskForm.rate" size="mini" @change="onRateChange"> <el-select v-model="taskForm.rate" size="mini" @change="onRateChange">
<el-option <el-option
@ -136,13 +128,22 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="taskForm.rate === 'CRON'" label=""> <el-form-item v-if="taskForm.rate === 'CRON'" label="">
<el-popover v-model="cronEdit"> <el-popover v-model="cronEdit">
<cron v-model="taskForm.cron" @close="cronEdit = false" /> <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-input slot="reference" v-model="taskForm.cron" size="mini" style="width: 50%" @click="cronEdit = true" />
</el-popover> </el-popover>
</el-form-item> </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-select v-model="taskForm.end" size="mini">
<el-option <el-option
:label="$t('dataset.no_limit')" :label="$t('dataset.no_limit')"