Merge branch 'temp' of http://1.14.125.6:3000/mianbin/ops-pro into temp
This commit is contained in:
commit
7e0f4345b6
@ -16,11 +16,6 @@ public class TargetManagerCreateReq {
|
|||||||
*/
|
*/
|
||||||
private String targetName;
|
private String targetName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
*/
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图标
|
* 图标
|
||||||
*/
|
*/
|
||||||
@ -45,4 +40,9 @@ public class TargetManagerCreateReq {
|
|||||||
* 文件大小(byte)
|
* 文件大小(byte)
|
||||||
*/
|
*/
|
||||||
private Double totalSize;
|
private Double totalSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织id
|
||||||
|
*/
|
||||||
|
private String projectId;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class TargetManagerResp{
|
|||||||
/**
|
/**
|
||||||
* 组织id
|
* 组织id
|
||||||
*/
|
*/
|
||||||
private Long orgId;
|
private String projectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图标
|
* 图标
|
||||||
|
@ -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;
|
||||||
@ -12,7 +11,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
@ -28,8 +26,8 @@ import java.util.concurrent.ScheduledFuture;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component("pipelineSchedulerConfig")
|
||||||
public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
||||||
@Resource
|
|
||||||
private ScheduledTaskRegistrar taskRegistrar;
|
private ScheduledTaskRegistrar taskRegistrar;
|
||||||
|
|
||||||
private final Map<String, ScheduledTask> taskFutures = new HashMap<>();
|
private final Map<String, ScheduledTask> taskFutures = new HashMap<>();
|
||||||
@ -39,10 +37,16 @@ public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void configureTasks(@NotNull ScheduledTaskRegistrar taskRegistrar) {
|
public void configureTasks(@NotNull ScheduledTaskRegistrar taskRegistrar) {
|
||||||
this.taskRegistrar = taskRegistrar;
|
this.taskRegistrar = taskRegistrar;
|
||||||
|
log.info("ScheduledTaskRegistrar 初始化完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addTask(String taskId, Runnable task, String cronExpression) {
|
public void addTask(String taskId, Runnable task, String cronExpression) {
|
||||||
|
if (taskRegistrar == null) {
|
||||||
|
log.error("【定时任务失败】taskRegistrar 尚未初始化,请检查调度器是否已启动");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CronTask cronTask = new CronTask(task, cronExpression);
|
CronTask cronTask = new CronTask(task, cronExpression);
|
||||||
ScheduledTask scheduledTask = taskRegistrar.scheduleCronTask(cronTask);
|
ScheduledTask scheduledTask = taskRegistrar.scheduleCronTask(cronTask);
|
||||||
taskFutures.put(taskId, scheduledTask);
|
taskFutures.put(taskId, scheduledTask);
|
||||||
@ -134,13 +138,13 @@ public class PipelineSchedulerConfig implements SchedulingConfigurer {
|
|||||||
return future != null && future.isCancelled();
|
return future != null && future.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
// @Component
|
||||||
public static class PipelineSchedulerTask implements Runnable {
|
// public static class PipelineSchedulerTask implements Runnable {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void run() {
|
// public void run() {
|
||||||
// 定时任务逻辑代码
|
// // 定时任务逻辑代码
|
||||||
System.out.println("Pipeline Task: " + new Date());
|
// System.out.println("Pipeline Task: " + new Date());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -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> {
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.engine.scheduler.dateObject;
|
|||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HopeLi
|
* @author HopeLi
|
||||||
@ -12,6 +13,7 @@ import lombok.Data;
|
|||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@TableName("pip_pipeline_scheduling_properties")
|
@TableName("pip_pipeline_scheduling_properties")
|
||||||
public class PipelineSchedulingProperties extends PipBaseElement {
|
public class PipelineSchedulingProperties extends PipBaseElement {
|
||||||
|
@ -30,15 +30,15 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTask(PipelineSchedulingProperties task) {
|
public void addTask(PipelineSchedulingProperties task) {
|
||||||
if (ContextStateEnum.RUNNING.getCode().equals(Integer.parseInt(task.getStatus()))) {
|
if (ContextStateEnum.RUNNING.getCode() == Integer.parseInt(task.getStatus())) {
|
||||||
taskScheduler.addTask(task.getPipelineId(), () -> {
|
pipelineSchedulerConfig.addTask(task.getPipelineId(), () -> {
|
||||||
},task.getCronExpression());
|
},task.getCronExpression());
|
||||||
}
|
}
|
||||||
taskRepository.insert(task);
|
taskRepository.insert(task);
|
||||||
@ -47,25 +47,25 @@ 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", String.valueOf(ContextStateEnum.RUNNING.getCode())).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", String.valueOf(ContextStateEnum.STOP.getCode())).eq("task_id", taskId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package cd.casic.ci.process.engine.scheduler.trigger;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName SchedulingTrigger
|
||||||
|
* @Date: 2025/5/27 15:05
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SchedulingTrigger {
|
||||||
|
@Scheduled(fixedRate = 5000)
|
||||||
|
public void triggerScheduler() {
|
||||||
|
// 用于触发调度器初始化
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,10 @@
|
|||||||
package cd.casic.ci.process.engine.worker;
|
package cd.casic.ci.process.engine.worker;
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.annotation.Plugin;
|
import cd.casic.ci.common.pipeline.annotation.Plugin;
|
||||||
import cd.casic.ci.process.engine.constant.EngineRuntimeConstant;
|
|
||||||
import cd.casic.ci.process.engine.context.ConstantContextHolder;
|
import cd.casic.ci.process.engine.context.ConstantContextHolder;
|
||||||
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
||||||
import cd.casic.ci.process.process.dataObject.log.PipTaskLog;
|
|
||||||
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
|
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
|
||||||
import cd.casic.ci.process.process.dataObject.target.TargetVersion;
|
import cd.casic.ci.process.process.dataObject.target.TargetVersion;
|
||||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
@ -36,11 +36,6 @@ public class TargetManager extends PipBaseElement {
|
|||||||
@TableField("target_type")
|
@TableField("target_type")
|
||||||
private String targetType;
|
private String targetType;
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
*/
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 描述
|
* 描述
|
||||||
*/
|
*/
|
||||||
@ -84,8 +79,8 @@ public class TargetManager extends PipBaseElement {
|
|||||||
/**
|
/**
|
||||||
* 组织id
|
* 组织id
|
||||||
*/
|
*/
|
||||||
@TableField("org_id")
|
@TableField("project_id")
|
||||||
private Long orgId;
|
private String projectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图标
|
* 图标
|
||||||
|
Loading…
x
Reference in New Issue
Block a user