Skip to content

Commit

Permalink
feat: taskControl的loop循环太久导致Consumer线程池被占满问题 TencentBlueKing#11352
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Jan 3, 2025
1 parent fb32c85 commit 5f032fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
}

// 失败的话就发终止事件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5f032fa

Please sign in to comment.