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