Merge pull request #13321 from dataease/pr@dev-v2@fixds
fix(数据源): api数据源定时任务无法停止
This commit is contained in:
commit
5bbb02a30b
@ -3,6 +3,7 @@ package io.dataease.datasource.dao.auto.entity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@ -64,11 +65,6 @@ public class CoreDatasourceTask implements Serializable {
|
||||
*/
|
||||
private String simpleCronType;
|
||||
|
||||
/**
|
||||
* 结束限制 0 无限制 1 设定结束时间
|
||||
*/
|
||||
private String endLimit;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@ -168,14 +164,6 @@ public class CoreDatasourceTask implements Serializable {
|
||||
this.simpleCronType = simpleCronType;
|
||||
}
|
||||
|
||||
public String getEndLimit() {
|
||||
return endLimit;
|
||||
}
|
||||
|
||||
public void setEndLimit(String endLimit) {
|
||||
this.endLimit = endLimit;
|
||||
}
|
||||
|
||||
public Long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
@ -236,7 +224,6 @@ public class CoreDatasourceTask implements Serializable {
|
||||
", cron = " + cron +
|
||||
", simpleCronValue = " + simpleCronValue +
|
||||
", simpleCronType = " + simpleCronType +
|
||||
", endLimit = " + endLimit +
|
||||
", endTime = " + endTime +
|
||||
", createTime = " + createTime +
|
||||
", lastExecTime = " + lastExecTime +
|
||||
|
||||
@ -324,7 +324,6 @@ public class DatasourceSyncManage {
|
||||
scheduleManager.getDefaultJobDataMap(datasourceTask.getDsId().toString(), datasourceTask.getCron(), datasourceTask.getId().toString(), datasourceTask.getUpdateType()));
|
||||
} else {
|
||||
Date endTime;
|
||||
if (StringUtils.equalsIgnoreCase(datasourceTask.getEndLimit().toString(), "1")) {
|
||||
if (datasourceTask.getEndTime() == null || datasourceTask.getEndTime() == 0) {
|
||||
endTime = null;
|
||||
} else {
|
||||
@ -334,9 +333,6 @@ public class DatasourceSyncManage {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
endTime = null;
|
||||
}
|
||||
|
||||
scheduleManager.addOrUpdateCronJob(new JobKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()),
|
||||
new TriggerKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()),
|
||||
|
||||
@ -288,7 +288,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getSyncRate(), RIGHTNOW.toString())) {
|
||||
coreDatasourceTask.setCron(null);
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1") && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
|
||||
if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0 && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
|
||||
DEException.throwException("结束时间不能小于开始时间!");
|
||||
}
|
||||
}
|
||||
@ -377,7 +377,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
coreDatasourceTask.setStartTime(System.currentTimeMillis() - 20 * 1000);
|
||||
coreDatasourceTask.setCron(null);
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1") && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
|
||||
if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0 && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
|
||||
DEException.throwException("结束时间不能小于开始时间!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ public class DatasourceTaskServer {
|
||||
coreDatasourceTask.setId(IDUtils.snowID());
|
||||
datasourceTaskMapper.insert(coreDatasourceTask);
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
datasourceTaskMapper.deleteById(id);
|
||||
}
|
||||
@ -101,8 +102,9 @@ public class DatasourceTaskServer {
|
||||
record.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||
datasourceTaskMapper.update(record, updateWrapper);
|
||||
}
|
||||
|
||||
public void checkTaskIsStopped(CoreDatasourceTask coreDatasourceTask) {
|
||||
if (coreDatasourceTask.getEndLimit() != null && StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1")) { // 结束限制 0 无限制 1 设定结束时间'
|
||||
if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0) {
|
||||
List<CoreDatasourceTaskDTO> dataSetTaskDTOS = taskWithTriggers(coreDatasourceTask.getId());
|
||||
if (CollectionUtils.isEmpty(dataSetTaskDTOS)) {
|
||||
return;
|
||||
@ -170,7 +172,7 @@ public class DatasourceTaskServer {
|
||||
if (coreDatasourceTask.getSyncRate().equalsIgnoreCase(ScheduleType.RIGHTNOW.name())) {
|
||||
record.setTaskStatus(TaskStatus.Stopped.name());
|
||||
} else {
|
||||
if (coreDatasourceTask.getEndLimit() != null && StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1")) {
|
||||
if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0) {
|
||||
List<CoreDatasourceTaskDTO> dataSetTaskDTOS = taskWithTriggers(coreDatasourceTask.getId());
|
||||
if (CollectionUtils.isEmpty(dataSetTaskDTOS)) {
|
||||
return;
|
||||
|
||||
@ -50,13 +50,11 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
|
||||
for (CoreDatasourceTask task : list) {
|
||||
try {
|
||||
if (!StringUtils.equalsIgnoreCase(task.getSyncRate(), DatasourceTaskServer.ScheduleType.RIGHTNOW.toString())) {
|
||||
if (StringUtils.equalsIgnoreCase(task.getEndLimit(), "1")) {
|
||||
if (task.getEndTime() != null && task.getEndTime() > 0) {
|
||||
if (task.getEndTime() > System.currentTimeMillis()) {
|
||||
datasourceSyncManage.addSchedule(task);
|
||||
}
|
||||
} else {
|
||||
datasourceSyncManage.addSchedule(task);
|
||||
datasourceSyncManage.deleteSchedule(task);
|
||||
}
|
||||
} else {
|
||||
datasourceSyncManage.addSchedule(task);
|
||||
@ -77,5 +75,4 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user