From 5f032fab90e6f62d37f32435bb7203f34f26510a Mon Sep 17 00:00:00 2001 From: carlyin Date: Fri, 3 Jan 2025 20:17:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20taskControl=E7=9A=84loop=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E5=A4=AA=E4=B9=85=E5=AF=BC=E8=87=B4Consumer=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0=E8=A2=AB=E5=8D=A0=E6=BB=A1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20#11352?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/vmbuild/EngineVMBuildService.kt | 44 +++++++++---------- .../process/engine/atom/TaskAtomService.kt | 30 +++++++++---- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt index 783445ad299..1738cca09c3 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/vmbuild/EngineVMBuildService.kt @@ -450,8 +450,10 @@ class EngineVMBuildService @Autowired(required = false) constructor( return false } val finalBuildStatus = getFinalBuildStatus(buildStatus, buildId, vmSeqId, startUpVMTask) - // 如果是完成状态,则更新构建机启动插件的状态 - if (finalBuildStatus.isFinish()) { + + // #2043 上报启动构建机状态时,重新刷新开始时间,以防止调度的耗时占用了Job的超时时间 + if (!startUpVMTask.status.isFinish() && finalBuildStatus.isFinish()) { // #2043 构建机当前启动状态是未结束状态,才进行刷新开始时间 + // 如果是完成状态,则更新构建机启动插件的状态 pipelineTaskService.updateTaskStatus( task = startUpVMTask, userId = startUpVMTask.starter, @@ -460,27 +462,23 @@ class EngineVMBuildService @Autowired(required = false) constructor( errorCode = errorCode, errorMsg = errorMsg ) - - // #2043 上报启动构建机状态时,重新刷新开始时间,以防止调度的耗时占用了Job的超时时间 - if (!startUpVMTask.status.isFinish()) { // #2043 构建机当前启动状态是未结束状态,才进行刷新开始时间 - pipelineContainerService.updateContainerStatus( - projectId = projectId, - buildId = buildId, - stageId = startUpVMTask.stageId, - containerId = startUpVMTask.containerId, - startTime = LocalDateTime.now(), - endTime = null, - buildStatus = BuildStatus.RUNNING - ) - containerBuildRecordService.containerStarted( - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId, - containerId = vmSeqId, - executeCount = startUpVMTask.executeCount ?: 1, - containerBuildStatus = finalBuildStatus - ) - } + pipelineContainerService.updateContainerStatus( + projectId = projectId, + buildId = buildId, + stageId = startUpVMTask.stageId, + containerId = startUpVMTask.containerId, + startTime = LocalDateTime.now(), + endTime = null, + buildStatus = BuildStatus.RUNNING + ) + containerBuildRecordService.containerStarted( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + containerId = vmSeqId, + executeCount = startUpVMTask.executeCount ?: 1, + containerBuildStatus = finalBuildStatus + ) } // 失败的话就发终止事件 diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/TaskAtomService.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/TaskAtomService.kt index ca877cc41e7..9ea0c9a9f26 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/TaskAtomService.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/atom/TaskAtomService.kt @@ -344,15 +344,27 @@ class TaskAtomService @Autowired(required = false) constructor( private fun log(atomResponse: AtomResponse, task: PipelineBuildTask, stopFlag: Boolean) { if (atomResponse.buildStatus.isFinish()) { - buildLogPrinter.addLine( - buildId = task.buildId, - message = "Task [${task.taskName}] ${atomResponse.buildStatus}!", - tag = task.taskId, - containerHashId = task.containerHashId, - executeCount = task.executeCount ?: 1, - jobId = null, - stepId = task.stepId - ) + if (atomResponse.errorCode != null) { + buildLogPrinter.addErrorLine( + buildId = task.buildId, + message = "Task [${task.taskName}] ${atomResponse.buildStatus} (${atomResponse.errorMsg})!", + tag = task.taskId, + containerHashId = task.containerHashId, + executeCount = task.executeCount ?: 1, + jobId = null, + stepId = task.stepId + ) + } else { + buildLogPrinter.addLine( + buildId = task.buildId, + message = "Task [${task.taskName}] ${atomResponse.buildStatus}!", + tag = task.taskId, + containerHashId = task.containerHashId, + executeCount = task.executeCount ?: 1, + jobId = null, + stepId = task.stepId + ) + } } else { if (stopFlag) { buildLogPrinter.addLine(