Skip to content

Commit

Permalink
Merge pull request #10608 from irwinsun/issue_8483
Browse files Browse the repository at this point in the history
fix:流水线删除后,执行中的任务没终止 #8483
  • Loading branch information
bkci-bot authored Jul 3, 2024
2 parents 27c38f1 + 5f1966d commit a7229b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ interface ServicePipelineResource {
@Parameter(description = "流水线ID", required = true)
@PathParam("pipelineId")
pipelineId: String,
@Parameter(description = "渠道号,默认为BS", required = false)
@Parameter(description = "渠道号,不指定则为空", required = false)
@QueryParam("channelCode")
channelCode: ChannelCode?
): Result<PipelineInfo?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class PipelineRuntimeService @Autowired constructor(
statusSet = setOf(
BuildStatus.RUNNING, BuildStatus.REVIEWING,
BuildStatus.QUEUE, BuildStatus.PREPARE_ENV,
BuildStatus.UNEXEC, BuildStatus.QUEUE_CACHE
BuildStatus.UNEXEC, BuildStatus.QUEUE_CACHE,
BuildStatus.STAGE_SUCCESS
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class BuildMonitorControl @Autowired constructor(
fun handle(event: PipelineBuildMonitorEvent): Boolean {

val buildId = event.buildId
val pipelineInfo = pipelineRepositoryService.getPipelineInfo(
projectId = event.projectId,
pipelineId = event.pipelineId,
channelCode = null
)
if (pipelineInfo == null) {
LOG.info("ENGINE|$buildId|BUILD_MONITOR|pipeline_deleted_cancel_monitor|ec=${event.executeCount}")
return true
}
val buildInfo = pipelineRuntimeService.getBuildInfo(event.projectId, buildId)
if (buildInfo == null || buildInfo.isFinish()) {
LOG.info("ENGINE|$buildId|BUILD_MONITOR|status=${buildInfo?.status}|ec=${event.executeCount}")
Expand All @@ -121,14 +130,18 @@ class BuildMonitorControl @Autowired constructor(
val minInterval = min(jobMinInt, stageMinInt)

if (minInterval < min(Timeout.CONTAINER_MAX_MILLS, Timeout.STAGE_MAX_MILLS)) {
LOG.info("ENGINE|${event.buildId}|BUILD_MONITOR_CONTINUE|jobMinInt=$jobMinInt|" +
"stageMinInt=$stageMinInt|Interval=$minInterval")
LOG.info(
"ENGINE|${event.buildId}|BUILD_MONITOR_CONTINUE|jobMinInt=$jobMinInt|" +
"stageMinInt=$stageMinInt|Interval=$minInterval"
)
// 每次Check间隔不能大于10分钟,防止长时间延迟消息被大量堆积
event.delayMills = coerceAtMost10Min(minInterval).toInt()
pipelineEventDispatcher.dispatch(event)
} else {
LOG.info("ENGINE|${event.buildId}|BUILD_MONITOR_QUIT|jobMinInt=$jobMinInt|" +
"stageMinInt=$stageMinInt|Interval=$minInterval")
LOG.info(
"ENGINE|${event.buildId}|BUILD_MONITOR_QUIT|jobMinInt=$jobMinInt|" +
"stageMinInt=$stageMinInt|Interval=$minInterval"
)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tencent.devops.common.event.listener.pipeline.BaseListener
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.notify.api.service.ServiceNotifyMessageTemplateResource
import com.tencent.devops.notify.pojo.SendNotifyMessageTemplateRequest
import com.tencent.devops.process.api.service.ServicePipelineResource
import com.tencent.devops.process.bean.PipelineUrlBean
import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_IN_REVIEW_STATUS
import com.tencent.devops.process.engine.pojo.event.PipelineBuildNotifyEvent
Expand All @@ -51,6 +52,16 @@ class PipelineBuildNotifyListener @Autowired constructor(
) : BaseListener<PipelineBuildNotifyEvent>(pipelineEventDispatcher) {

override fun run(event: PipelineBuildNotifyEvent) {
try {
val pipelineNotDeleted = client.get(ServicePipelineResource::class)
.getPipelineInfo(projectId = event.projectId, pipelineId = event.pipelineId, channelCode = null).data
if (pipelineNotDeleted == null) {
logger.warn("NOTIFY|CHECK_PIPE|Pipeline[${event.projectId}/${event.pipelineId}] may be deleted!")
return
}
} catch (ignore: Exception) {
logger.warn("NOTIFY|CHECK_PIPE|SKIP_ERROR_CHECK", ignore)
}
when (val notifyTemplateEnumType = PipelineNotifyTemplateEnum.parse(event.notifyTemplateEnum)) {
PipelineNotifyTemplateEnum.PIPELINE_MANUAL_REVIEW_STAGE_NOTIFY_TEMPLATE,
PipelineNotifyTemplateEnum.PIPELINE_MANUAL_REVIEW_ATOM_NOTIFY_TEMPLATE,
Expand All @@ -77,9 +88,11 @@ class PipelineBuildNotifyListener @Autowired constructor(
)
}
}

PipelineNotifyTemplateEnum.PIPELINE_MANUAL_REVIEW_ATOM_REMINDER_NOTIFY_TEMPLATE -> {
event.sendReviewReminder()
}

else -> {
// need to add
}
Expand Down

0 comments on commit a7229b5

Please sign in to comment.