Преглед изворни кода

feat: 配置线程池并发限制

weipengtao пре 10 месеци
родитељ
комит
bc4e3a452d

+ 22 - 22
web/src/main/java/cn/seecoder/web/controller/pipeline/DeploymentController.java

@@ -1,5 +1,10 @@
 package cn.seecoder.web.controller.pipeline;
 package cn.seecoder.web.controller.pipeline;
 
 
+import cn.seecoder.common.exceptions.AccessDeniedException;
+import cn.seecoder.common.exceptions.ServiceException;
+import cn.seecoder.web.model.vo.Response;
+import cn.seecoder.web.model.vo.pipeline.DeploymentInfoVO;
+import cn.seecoder.web.service.pipeline.DeploymentService;
 import cn.seecoder.web.service.user.UserService;
 import cn.seecoder.web.service.user.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParam;
@@ -7,11 +12,6 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
-import cn.seecoder.common.exceptions.AccessDeniedException;
-import cn.seecoder.common.exceptions.ServiceException;
-import cn.seecoder.web.model.vo.Response;
-import cn.seecoder.web.model.vo.pipeline.DeploymentInfoVO;
-import cn.seecoder.web.service.pipeline.DeploymentService;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -33,45 +33,45 @@ public class DeploymentController {
     }
     }
 
 
     @ApiOperation(value = "获取项目所有部署的实例信息", httpMethod = "GET")
     @ApiOperation(value = "获取项目所有部署的实例信息", httpMethod = "GET")
-    @ApiImplicitParam(name = "projectId", dataType ="int", paramType = "query")
+    @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query")
     @GetMapping("/list")
     @GetMapping("/list")
-    public Response<List<DeploymentInfoVO>> retrieveDeploymentInfos(@RequestParam("projectId")Integer projectId) throws AccessDeniedException {
+    public Response<List<DeploymentInfoVO>> retrieveDeploymentInfos(@RequestParam("projectId") Integer projectId) throws AccessDeniedException {
         return Response.buildSuccess(deploymentService.retrieveDeploymentInfos(projectId));
         return Response.buildSuccess(deploymentService.retrieveDeploymentInfos(projectId));
     }
     }
 
 
 
 
     @ApiOperation(value = "执行流水线构建实例", httpMethod = "POST")
     @ApiOperation(value = "执行流水线构建实例", httpMethod = "POST")
     @ApiImplicitParams({
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
-            @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
+            @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
+            @ApiImplicitParam(name = "pipelineId", dataType = "int", paramType = "query")
     })
     })
     @PostMapping
     @PostMapping
-    public Response deploy(@RequestParam("projectId")Integer projectId,
-                           @RequestParam("pipelineId")Integer pipelineId) throws ServiceException {
-        deploymentService.deploy(projectId,pipelineId, UserService.loginUser().getId());
+    public Response deploy(@RequestParam("projectId") Integer projectId,
+                           @RequestParam("pipelineId") Integer pipelineId) throws ServiceException {
+        deploymentService.deploy(projectId, pipelineId, UserService.loginUser().getId());
         return Response.buildSuccess();
         return Response.buildSuccess();
     }
     }
 
 
     @ApiOperation(value = "删除一个部署的实例", httpMethod = "DELETE")
     @ApiOperation(value = "删除一个部署的实例", httpMethod = "DELETE")
     @ApiImplicitParams({
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
-            @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
+            @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
+            @ApiImplicitParam(name = "pipelineId", dataType = "int", paramType = "query")
     })
     })
     @DeleteMapping
     @DeleteMapping
-    public Response delete(@RequestParam("projectId")Integer projectId,
-                @RequestParam("pipelineId")Integer pipelineId) throws ServiceException {
-        deploymentService.delete(projectId,pipelineId);
+    public Response delete(@RequestParam("projectId") Integer projectId,
+                           @RequestParam("pipelineId") Integer pipelineId) throws ServiceException {
+        deploymentService.delete(projectId, pipelineId);
         return Response.buildSuccess();
         return Response.buildSuccess();
     }
     }
 
 
     @ApiOperation(value = "获取一个部署的实例的日志", httpMethod = "GET")
     @ApiOperation(value = "获取一个部署的实例的日志", httpMethod = "GET")
     @ApiImplicitParams({
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
-            @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
+            @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
+            @ApiImplicitParam(name = "pipelineId", dataType = "int", paramType = "query")
     })
     })
     @GetMapping("/log")
     @GetMapping("/log")
-    public Response log(@RequestParam("projectId")Integer projectId,
-                           @RequestParam("pipelineId")Integer pipelineId) throws ServiceException {
-        return Response.buildSuccess(deploymentService.log(projectId,pipelineId));
+    public Response log(@RequestParam("projectId") Integer projectId,
+                        @RequestParam("pipelineId") Integer pipelineId) throws ServiceException {
+        return Response.buildSuccess(deploymentService.log(projectId, pipelineId));
     }
     }
 }
 }

+ 22 - 0
web/src/main/java/cn/seecoder/web/infrastructure/config/AsyncConfig.java

@@ -0,0 +1,22 @@
+package cn.seecoder.web.infrastructure.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+@Configuration
+@EnableAsync
+public class AsyncConfig {
+
+    @Bean(name = "deployExecutor")
+    public ThreadPoolTaskExecutor deployExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(3);  // 同时最多执行3个deploy
+        executor.setMaxPoolSize(3);
+        executor.setQueueCapacity(10); // 队列等待任务数量
+        executor.setThreadNamePrefix("deploy-");
+        executor.initialize();
+        return executor;
+    }
+}

+ 1 - 1
web/src/main/java/cn/seecoder/web/service/impl/pipeline/DeploymentServiceImpl.java

@@ -103,7 +103,7 @@ public class DeploymentServiceImpl implements DeploymentService {
      * 部署指定项目流水线
      * 部署指定项目流水线
      */
      */
     @Override
     @Override
-    @Async
+    @Async("deployExecutor")
     public void deploy(Integer projectId, Integer pipelineId, Integer userId) throws ServiceException {
     public void deploy(Integer projectId, Integer pipelineId, Integer userId) throws ServiceException {
         PipelinePO pipelinePO = pipelineMapper.selectById(pipelineId);
         PipelinePO pipelinePO = pipelineMapper.selectById(pipelineId);
         ProjectPO projectPO = projectMapper.getProjectById(projectId);
         ProjectPO projectPO = projectMapper.getProjectById(projectId);