Просмотр исходного кода

调整 DeployJob 中健康检查的逻辑, 在应用部署后使用 10s 的时间进行健康检查, 然后发送健康检查的结果

reghao 2 дней назад
Родитель
Сommit
fefbe97580
1 измененных файлов с 15 добавлено и 3 удалено
  1. 15 3
      agent/src/main/java/cn/reghao/devops/agent/service/DeployJob.java

+ 15 - 3
agent/src/main/java/cn/reghao/devops/agent/service/DeployJob.java

@@ -57,7 +57,20 @@ public class DeployJob  {
 
             log.info(">>> [Step 4] 正在轮询健康检查...");
             int maxRetries = 5; // 假设尝试 5 次,每次 2s
-            for (int i = 0; i < maxRetries; i++) {
+            runStep(ctx, DeployStepName.HEALTH_CHECK.name(), () -> {
+                for (int i = 0; i < maxRetries; i++) {
+                    try (Socket socket = new Socket()) {
+                        // 仅检测 TCP 端口是否开放,无需 curl
+                        String host = "localhost";
+                        socket.connect(new InetSocketAddress(host, appPort), 2000);
+                        //healthCheck = true;
+                    } catch (IOException e) {
+                        //throw new RuntimeException(e);
+                    }
+                    try { Thread.sleep(2000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
+                }
+            });
+            /*for (int i = 0; i < maxRetries; i++) {
                 runStep(ctx, DeployStepName.HEALTH_CHECK.name(), () -> {
                     try (Socket socket = new Socket()) {
                         // 仅检测 TCP 端口是否开放,无需 curl
@@ -69,8 +82,7 @@ public class DeployJob  {
                     }
                 });
                 try { Thread.sleep(2000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
-            }
-
+            }*/
             runStep(ctx, DeployStepName.DEPLOY_DONE.name(), () -> {
                 log.info(">>> [Step 5] 上报部署状态...");
                 InspectContainerResponse inspectContainerResponse = DockerManager.getDocker().inspectContainer(appId);