Merge pull request #13321 from dataease/pr@dev-v2@fixds

fix(数据源): api数据源定时任务无法停止
This commit is contained in:
taojinlong 2024-11-14 15:42:21 +08:00 committed by GitHub
commit 5bbb02a30b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 65 deletions

View File

@ -3,6 +3,7 @@ package io.dataease.datasource.dao.auto.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -64,11 +65,6 @@ public class CoreDatasourceTask implements Serializable {
*/ */
private String simpleCronType; private String simpleCronType;
/**
* 结束限制 0 无限制 1 设定结束时间
*/
private String endLimit;
/** /**
* 结束时间 * 结束时间
*/ */
@ -168,14 +164,6 @@ public class CoreDatasourceTask implements Serializable {
this.simpleCronType = simpleCronType; this.simpleCronType = simpleCronType;
} }
public String getEndLimit() {
return endLimit;
}
public void setEndLimit(String endLimit) {
this.endLimit = endLimit;
}
public Long getEndTime() { public Long getEndTime() {
return endTime; return endTime;
} }
@ -236,7 +224,6 @@ public class CoreDatasourceTask implements Serializable {
", cron = " + cron + ", cron = " + cron +
", simpleCronValue = " + simpleCronValue + ", simpleCronValue = " + simpleCronValue +
", simpleCronType = " + simpleCronType + ", simpleCronType = " + simpleCronType +
", endLimit = " + endLimit +
", endTime = " + endTime + ", endTime = " + endTime +
", createTime = " + createTime + ", createTime = " + createTime +
", lastExecTime = " + lastExecTime + ", lastExecTime = " + lastExecTime +

View File

@ -324,7 +324,6 @@ public class DatasourceSyncManage {
scheduleManager.getDefaultJobDataMap(datasourceTask.getDsId().toString(), datasourceTask.getCron(), datasourceTask.getId().toString(), datasourceTask.getUpdateType())); scheduleManager.getDefaultJobDataMap(datasourceTask.getDsId().toString(), datasourceTask.getCron(), datasourceTask.getId().toString(), datasourceTask.getUpdateType()));
} else { } else {
Date endTime; Date endTime;
if (StringUtils.equalsIgnoreCase(datasourceTask.getEndLimit().toString(), "1")) {
if (datasourceTask.getEndTime() == null || datasourceTask.getEndTime() == 0) { if (datasourceTask.getEndTime() == null || datasourceTask.getEndTime() == 0) {
endTime = null; endTime = null;
} else { } else {
@ -334,9 +333,6 @@ public class DatasourceSyncManage {
return; return;
} }
} }
} else {
endTime = null;
}
scheduleManager.addOrUpdateCronJob(new JobKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()), scheduleManager.addOrUpdateCronJob(new JobKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()),
new TriggerKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()), new TriggerKey(datasourceTask.getId().toString(), datasourceTask.getDsId().toString()),

View File

@ -288,7 +288,7 @@ public class DatasourceServer implements DatasourceApi {
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getSyncRate(), RIGHTNOW.toString())) { if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getSyncRate(), RIGHTNOW.toString())) {
coreDatasourceTask.setCron(null); coreDatasourceTask.setCron(null);
} else { } else {
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1") && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) { if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0 && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
DEException.throwException("结束时间不能小于开始时间!"); DEException.throwException("结束时间不能小于开始时间!");
} }
} }
@ -377,7 +377,7 @@ public class DatasourceServer implements DatasourceApi {
coreDatasourceTask.setStartTime(System.currentTimeMillis() - 20 * 1000); coreDatasourceTask.setStartTime(System.currentTimeMillis() - 20 * 1000);
coreDatasourceTask.setCron(null); coreDatasourceTask.setCron(null);
} else { } else {
if (StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1") && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) { if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0 && coreDatasourceTask.getStartTime() > coreDatasourceTask.getEndTime()) {
DEException.throwException("结束时间不能小于开始时间!"); DEException.throwException("结束时间不能小于开始时间!");
} }
} }

View File

@ -79,6 +79,7 @@ public class DatasourceTaskServer {
coreDatasourceTask.setId(IDUtils.snowID()); coreDatasourceTask.setId(IDUtils.snowID());
datasourceTaskMapper.insert(coreDatasourceTask); datasourceTaskMapper.insert(coreDatasourceTask);
} }
public void delete(Long id) { public void delete(Long id) {
datasourceTaskMapper.deleteById(id); datasourceTaskMapper.deleteById(id);
} }
@ -101,8 +102,9 @@ public class DatasourceTaskServer {
record.setTaskStatus(TaskStatus.WaitingForExecution.name()); record.setTaskStatus(TaskStatus.WaitingForExecution.name());
datasourceTaskMapper.update(record, updateWrapper); datasourceTaskMapper.update(record, updateWrapper);
} }
public void checkTaskIsStopped(CoreDatasourceTask coreDatasourceTask) { 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()); List<CoreDatasourceTaskDTO> dataSetTaskDTOS = taskWithTriggers(coreDatasourceTask.getId());
if (CollectionUtils.isEmpty(dataSetTaskDTOS)) { if (CollectionUtils.isEmpty(dataSetTaskDTOS)) {
return; return;
@ -170,7 +172,7 @@ public class DatasourceTaskServer {
if (coreDatasourceTask.getSyncRate().equalsIgnoreCase(ScheduleType.RIGHTNOW.name())) { if (coreDatasourceTask.getSyncRate().equalsIgnoreCase(ScheduleType.RIGHTNOW.name())) {
record.setTaskStatus(TaskStatus.Stopped.name()); record.setTaskStatus(TaskStatus.Stopped.name());
} else { } else {
if (coreDatasourceTask.getEndLimit() != null && StringUtils.equalsIgnoreCase(coreDatasourceTask.getEndLimit(), "1")) { if (coreDatasourceTask.getEndTime() != null && coreDatasourceTask.getEndTime() > 0) {
List<CoreDatasourceTaskDTO> dataSetTaskDTOS = taskWithTriggers(coreDatasourceTask.getId()); List<CoreDatasourceTaskDTO> dataSetTaskDTOS = taskWithTriggers(coreDatasourceTask.getId());
if (CollectionUtils.isEmpty(dataSetTaskDTOS)) { if (CollectionUtils.isEmpty(dataSetTaskDTOS)) {
return; return;

View File

@ -50,13 +50,11 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
for (CoreDatasourceTask task : list) { for (CoreDatasourceTask task : list) {
try { try {
if (!StringUtils.equalsIgnoreCase(task.getSyncRate(), DatasourceTaskServer.ScheduleType.RIGHTNOW.toString())) { 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() != null && task.getEndTime() > 0) {
if (task.getEndTime() > System.currentTimeMillis()) { if (task.getEndTime() > System.currentTimeMillis()) {
datasourceSyncManage.addSchedule(task); datasourceSyncManage.addSchedule(task);
}
} else { } else {
datasourceSyncManage.addSchedule(task); datasourceSyncManage.deleteSchedule(task);
} }
} else { } else {
datasourceSyncManage.addSchedule(task); datasourceSyncManage.addSchedule(task);
@ -77,5 +75,4 @@ public class DataSourceInitStartListener implements ApplicationListener<Applicat
} }
} }