后置处理逻辑

This commit is contained in:
even 2025-07-29 18:53:30 +08:00
parent d5bb9b1404
commit 3cb633c938
2 changed files with 17 additions and 1 deletions

View File

@ -46,4 +46,16 @@ public class ExecutorConfig {
executor.initialize(); // 必须手动触发初始化 executor.initialize(); // 必须手动触发初始化
return executor; return executor;
} }
@Bean("postHandlerExecutor")
public ThreadPoolTaskExecutor postHandlerExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("postHandler-");
ThreadPoolExecutor.CallerRunsPolicy callerRunsPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
executor.setRejectedExecutionHandler(callerRunsPolicy);
executor.initialize(); // 必须手动触发初始化
return executor;
}
} }

View File

@ -5,7 +5,9 @@ import cd.casic.ci.process.engine.postHandler.ExecuteTaskPostHandler;
import cd.casic.ci.process.process.dataObject.history.PipPipelineHisInstance; import cd.casic.ci.process.process.dataObject.history.PipPipelineHisInstance;
import cd.casic.framework.commons.exception.ServiceException; import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants; import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -16,6 +18,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
@Component @Component
public class MemoryPostHandlerManager implements PostHandlerManager { public class MemoryPostHandlerManager implements PostHandlerManager {
private final ConcurrentHashMap<String, List<ExecuteTaskPostHandler>> handlerMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, List<ExecuteTaskPostHandler>> handlerMap = new ConcurrentHashMap<>();
@Resource
private ThreadPoolTaskExecutor postHandlerExecutor;
@Override @Override
public void registerPostHandler(ExecuteTaskPostHandler handler) { public void registerPostHandler(ExecuteTaskPostHandler handler) {
if (handler==null|| StringUtils.isEmpty(handler.getPipelineId())) { if (handler==null|| StringUtils.isEmpty(handler.getPipelineId())) {
@ -34,7 +38,7 @@ public class MemoryPostHandlerManager implements PostHandlerManager {
return; return;
} }
for (ExecuteTaskPostHandler postHandler : pipExecutePostHandlers) { for (ExecuteTaskPostHandler postHandler : pipExecutePostHandlers) {
postHandler.executeAfterDone(hisInstance); postHandlerExecutor.submit(()->postHandler.executeAfterDone(hisInstance));
} }
} }
} }