0527 ljc
This commit is contained in:
parent
b8e344547a
commit
bf858cfe21
@ -26,7 +26,7 @@ public class PipelineSchedulingBootstrapper {
|
|||||||
private PipelineSchedulingPropertiesServiceImpl taskService;
|
private PipelineSchedulingPropertiesServiceImpl taskService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PipelineSchedulerConfig taskScheduler;
|
private PipelineSchedulerConfig pipelineSchedulerConfig;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PipelineExecutor pipelineExecutor;
|
private PipelineExecutor pipelineExecutor;
|
||||||
@ -36,7 +36,7 @@ public class PipelineSchedulingBootstrapper {
|
|||||||
List<PipelineSchedulingProperties> tasks = taskService.getAllTasks();
|
List<PipelineSchedulingProperties> tasks = taskService.getAllTasks();
|
||||||
for (PipelineSchedulingProperties task : tasks) {
|
for (PipelineSchedulingProperties task : tasks) {
|
||||||
if (ContextStateEnum.RUNNING.getCode().equals(Integer.parseInt(task.getStatus()))) {
|
if (ContextStateEnum.RUNNING.getCode().equals(Integer.parseInt(task.getStatus()))) {
|
||||||
taskScheduler.addTask(task.getPipelineId(), ()->{
|
pipelineSchedulerConfig.addTask(task.getPipelineId(), ()->{
|
||||||
pipelineExecutor.execute(task.getPipelineId());
|
pipelineExecutor.execute(task.getPipelineId());
|
||||||
}, task.getCronExpression());
|
}, task.getCronExpression());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cd.casic.ci.process.engine.scheduler.config;
|
package cd.casic.ci.process.engine.scheduler.config;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -28,8 +27,9 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component("pipelineSchedulerConfig")
|
||||||
public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
||||||
@Resource
|
// @Resource
|
||||||
private ScheduledTaskRegistrar taskRegistrar;
|
private ScheduledTaskRegistrar taskRegistrar;
|
||||||
|
|
||||||
private final Map<String, ScheduledTask> taskFutures = new HashMap<>();
|
private final Map<String, ScheduledTask> taskFutures = new HashMap<>();
|
||||||
|
@ -2,6 +2,7 @@ package cd.casic.ci.process.engine.scheduler.dao;
|
|||||||
|
|
||||||
import cd.casic.ci.process.engine.scheduler.dateObject.PipelineSchedulingProperties;
|
import cd.casic.ci.process.engine.scheduler.dateObject.PipelineSchedulingProperties;
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HopeLi
|
* @author HopeLi
|
||||||
@ -10,5 +11,6 @@ import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|||||||
* @Date: 2025/5/26 16:31
|
* @Date: 2025/5/26 16:31
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface PipelineSchedulingPropertiesDao extends BaseMapperX<PipelineSchedulingProperties> {
|
public interface PipelineSchedulingPropertiesDao extends BaseMapperX<PipelineSchedulingProperties> {
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class PipelineSchedulingPropertiesServiceImpl extends ServiceImpl<Pipelin
|
|||||||
private PipelineSchedulingPropertiesDao taskRepository;
|
private PipelineSchedulingPropertiesDao taskRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PipelineSchedulerConfig taskScheduler;
|
private PipelineSchedulerConfig pipelineSchedulerConfig;
|
||||||
|
|
||||||
public List<PipelineSchedulingProperties> getAllTasks() {
|
public List<PipelineSchedulingProperties> getAllTasks() {
|
||||||
return taskRepository.selectList(null);
|
return taskRepository.selectList(null);
|
||||||
@ -38,7 +38,7 @@ public class PipelineSchedulingPropertiesServiceImpl extends ServiceImpl<Pipelin
|
|||||||
|
|
||||||
public void addTask(PipelineSchedulingProperties task) {
|
public void addTask(PipelineSchedulingProperties task) {
|
||||||
if (ContextStateEnum.RUNNING.getCode().equals(Integer.parseInt(task.getStatus()))) {
|
if (ContextStateEnum.RUNNING.getCode().equals(Integer.parseInt(task.getStatus()))) {
|
||||||
taskScheduler.addTask(task.getPipelineId(), () -> {
|
pipelineSchedulerConfig.addTask(task.getPipelineId(), () -> {
|
||||||
},task.getCronExpression());
|
},task.getCronExpression());
|
||||||
}
|
}
|
||||||
taskRepository.insert(task);
|
taskRepository.insert(task);
|
||||||
@ -47,24 +47,24 @@ public class PipelineSchedulingPropertiesServiceImpl extends ServiceImpl<Pipelin
|
|||||||
public void updateTask(PipelineSchedulingProperties task) {
|
public void updateTask(PipelineSchedulingProperties task) {
|
||||||
PipelineSchedulingProperties old = taskRepository.selectById(task.getId());
|
PipelineSchedulingProperties old = taskRepository.selectById(task.getId());
|
||||||
if (old != null) {
|
if (old != null) {
|
||||||
taskScheduler.updateTask(old.getPipelineId(), task.getCronExpression());
|
pipelineSchedulerConfig.updateTask(old.getPipelineId(), task.getCronExpression());
|
||||||
}
|
}
|
||||||
taskRepository.updateById(task);
|
taskRepository.updateById(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteTask(String taskId) {
|
public void deleteTask(String taskId) {
|
||||||
taskScheduler.removeTask(taskId);
|
pipelineSchedulerConfig.removeTask(taskId);
|
||||||
taskRepository.delete(new QueryWrapper<PipelineSchedulingProperties>().eq("task_id", taskId));
|
taskRepository.delete(new QueryWrapper<PipelineSchedulingProperties>().eq("task_id", taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTask(String taskId) {
|
public void startTask(String taskId) {
|
||||||
taskScheduler.startTask(taskId);
|
pipelineSchedulerConfig.startTask(taskId);
|
||||||
taskRepository.update(null, new UpdateWrapper<PipelineSchedulingProperties>()
|
taskRepository.update(null, new UpdateWrapper<PipelineSchedulingProperties>()
|
||||||
.set("status", "RUNNING").eq("task_id", taskId));
|
.set("status", "RUNNING").eq("task_id", taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTask(String taskId) {
|
public void stopTask(String taskId) {
|
||||||
taskScheduler.stopTask(taskId);
|
pipelineSchedulerConfig.stopTask(taskId);
|
||||||
taskRepository.update(null, new UpdateWrapper<PipelineSchedulingProperties>()
|
taskRepository.update(null, new UpdateWrapper<PipelineSchedulingProperties>()
|
||||||
.set("status", "STOPPED").eq("task_id", taskId));
|
.set("status", "STOPPED").eq("task_id", taskId));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user