Skip to content

Commit

Permalink
pref:流水线构建重试时增加时间限制 TencentBlueKing#11478
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Feb 19, 2025
1 parent 4fd3b24 commit 09897b6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ val shardingDbTableCheckTask = tasks.register("shardingDbTableCheck") {
ModuleUtil.getBkModuleName(project.name, project.findProperty("i18n.module.name")?.toString())
val moduleNames = ModuleUtil.getBkActualModuleNames(bkModuleName)
moduleNames.forEach { moduleName ->
var (mysqlURL, mysqlUser, mysqlPasswd) = DatabaseUtil.getMysqlInfo(
val (mysqlURL, mysqlUser, mysqlPasswd) = DatabaseUtil.getMysqlInfo(
moduleName = moduleName,
defaultMysqlURL = project.extra["DB_HOST"]?.toString(),
defaultMysqlUser = project.extra["DB_USERNAME"]?.toString(),
Expand All @@ -47,7 +47,7 @@ val shardingDbTableCheckTask = tasks.register("shardingDbTableCheck") {
if (moduleName in listOf("process", "engine") && archiveDbUrls == null) {
archiveDbUrls = normalDbUrls
}
if ((!normalDbUrls.isEmpty() && normalDbUrls.size > 1) || archiveDbUrls?.isEmpty() == false) {
if ((normalDbUrls.isNotEmpty() && normalDbUrls.size > 1) || archiveDbUrls?.isEmpty() == false) {
val databaseName = DatabaseUtil.getDatabaseName(moduleName, project.extra["DB_PREFIX"].toString())
// 各普通DB的表进行比较
val referNormalDb = doCompareDatabasesBus(
Expand Down Expand Up @@ -308,27 +308,28 @@ fun compareColumns(
compareDbUrl: String,
compareDatabaseName: String
) {
if (referenceTable.columns != compareTable.columns) {
var missingColumns = referenceTable.columns - compareTable.columns
var extraColumns = compareTable.columns - referenceTable.columns
val mismatchColumns = mutableListOf<ColumnInfo>()
val missingColumnNames = missingColumns.map { it.name }
extraColumns.forEach { extraColumn ->
if (missingColumnNames.contains(extraColumn.name)) {
mismatchColumns.add(extraColumn)
}
if (referenceTable.columns == compareTable.columns) {
return
}
var missingColumns = referenceTable.columns - compareTable.columns.toSet()
var extraColumns = compareTable.columns - referenceTable.columns.toSet()
val mismatchColumns = mutableListOf<ColumnInfo>()
val missingColumnNames = missingColumns.map { it.name }
extraColumns.forEach { extraColumn ->
if (missingColumnNames.contains(extraColumn.name)) {
mismatchColumns.add(extraColumn)
}
val mismatchColumnNames = mismatchColumns.map { it.name }
missingColumns = missingColumns.filter { !mismatchColumnNames.contains(it.name) }
extraColumns = extraColumns - mismatchColumns
val columnTip = "Compared with the table of database ($referenceDbUrl/$referenceDatabaseName), " +
}
val mismatchColumnNames = mismatchColumns.map { it.name }
missingColumns = missingColumns.filter { !mismatchColumnNames.contains(it.name) }
extraColumns = extraColumns - mismatchColumns.toSet()
val columnTip = "Compared with the table of database ($referenceDbUrl/$referenceDatabaseName), " +
"the differences of table ($tableName) of database ($compareDbUrl/$compareDatabaseName) are as " +
"follows: missing columns: $missingColumns; extra columns: $extraColumns; " +
"different columns: $mismatchColumns."
if (!missingColumns.isNullOrEmpty() || !extraColumns.isNullOrEmpty() || !mismatchColumns.isNullOrEmpty()) {
// 字段有差异则抛出错误提示
throw RuntimeException(columnTip)
}
if (missingColumns.isNotEmpty() || extraColumns.isNotEmpty() || mismatchColumns.isNotEmpty()) {
// 字段有差异则抛出错误提示
throw RuntimeException(columnTip)
}
}

Expand All @@ -341,26 +342,27 @@ fun compareIndexes(
compareDbUrl: String,
compareDatabaseName: String
) {
if (referenceTable.indexes != compareTable.indexes) {
var missingIndexes = referenceTable.indexes - compareTable.indexes
var extraIndexes = compareTable.indexes - referenceTable.indexes
val mismatchIndexes = mutableListOf<IndexInfo>()
val missingIndexNames = missingIndexes.map { it.name }
extraIndexes.forEach { extraIndex ->
if (missingIndexNames.contains(extraIndex.name)) {
mismatchIndexes.add(extraIndex)
}
if (referenceTable.indexes == compareTable.indexes) {
return
}
var missingIndexes = referenceTable.indexes - compareTable.indexes.toSet()
var extraIndexes = compareTable.indexes - referenceTable.indexes.toSet()
val mismatchIndexes = mutableListOf<IndexInfo>()
val missingIndexNames = missingIndexes.map { it.name }
extraIndexes.forEach { extraIndex ->
if (missingIndexNames.contains(extraIndex.name)) {
mismatchIndexes.add(extraIndex)
}
val mismatchIndexNames = mismatchIndexes.map { it.name }
missingIndexes = missingIndexes.filter { !mismatchIndexNames.contains(it.name) }
extraIndexes = extraIndexes - mismatchIndexes
val indexTip = "Compared with the table of database ($referenceDbUrl/$referenceDatabaseName), " +
}
val mismatchIndexNames = mismatchIndexes.map { it.name }
missingIndexes = missingIndexes.filter { !mismatchIndexNames.contains(it.name) }
extraIndexes = extraIndexes - mismatchIndexes.toSet()
val indexTip = "Compared with the table of database ($referenceDbUrl/$referenceDatabaseName), " +
"the differences of table ($tableName) of database ($compareDbUrl/$compareDatabaseName) are as " +
"follows: missing indexs: $missingIndexes; extra indexs: $extraIndexes; " +
"different indexs: $mismatchIndexes."
if (!missingIndexes.isNullOrEmpty() || !extraIndexes.isNullOrEmpty() || !mismatchIndexes.isNullOrEmpty()) {
// 字段有差异则抛出错误提示
throw RuntimeException(indexTip)
}
if (missingIndexes.isNotEmpty() || extraIndexes.isNotEmpty() || mismatchIndexes.isNotEmpty()) {
// 字段有差异则抛出错误提示
throw RuntimeException(indexTip)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ import com.tencent.devops.common.api.pojo.ErrorType
import com.tencent.devops.common.api.pojo.IdValue
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.pojo.SimpleResult
import com.tencent.devops.common.api.util.DateTimeUtil
import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.api.util.PageUtil
import com.tencent.devops.common.api.util.timestampmilli
import com.tencent.devops.common.audit.ActionAuditContent
import com.tencent.devops.common.auth.api.ActionId
import com.tencent.devops.common.auth.api.AuthPermission
Expand Down Expand Up @@ -130,7 +132,6 @@ import com.tencent.devops.process.service.BuildVariableService
import com.tencent.devops.process.service.ParamFacadeService
import com.tencent.devops.process.service.PipelineTaskPauseService
import com.tencent.devops.process.service.pipeline.PipelineBuildService
import com.tencent.devops.process.service.template.TemplateFacadeService
import com.tencent.devops.process.strategy.context.UserPipelinePermissionCheckContext
import com.tencent.devops.process.strategy.factory.UserPipelinePermissionCheckStrategyFactory
import com.tencent.devops.process.util.TaskUtils
Expand All @@ -148,6 +149,9 @@ import com.tencent.devops.quality.api.v2.pojo.ControlPointPosition
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.util.concurrent.TimeUnit
import javax.ws.rs.core.Response
import javax.ws.rs.core.UriBuilder
Expand Down Expand Up @@ -182,13 +186,15 @@ class PipelineBuildFacadeService(
private val pipelineRedisService: PipelineRedisService,
private val pipelineRetryFacadeService: PipelineRetryFacadeService,
private val webhookBuildParameterService: WebhookBuildParameterService,
private val pipelineYamlFacadeService: PipelineYamlFacadeService,
private val templateFacadeService: TemplateFacadeService
private val pipelineYamlFacadeService: PipelineYamlFacadeService
) {

@Value("\${pipeline.build.cancel.intervalLimitTime:60}")
private var cancelIntervalLimitTime: Int = 60 // 取消间隔时间为60秒

@Value("\${pipeline.build.retry.limit_days:21}")
private var retryLimitDays: Int = 21

companion object {
private val logger = LoggerFactory.getLogger(PipelineBuildFacadeService::class.java)
private const val RETRY_THIRD_AGENT_ENV = "RETRY_THIRD_AGENT_ENV"
Expand Down Expand Up @@ -415,6 +421,14 @@ class PipelineBuildFacadeService(
if (buildInfo.pipelineId != pipelineId) {
throw ErrorCodeException(errorCode = ProcessMessageCode.ERROR_PIPLEINE_INPUT)
}
buildInfo.startTime?.let {
// 判断当前时间是否超过最大重试时间
if (LocalDateTime.now().minusDays(retryLimitDays.toLong()).timestampmilli() - it < 0) {
throw ErrorCodeException(
errorCode = ProcessMessageCode.ERROR_BUILD_EXPIRED_CANT_RETRY
)
}
}

// 运行中的task重试走全新的处理逻辑
if (!buildInfo.isFinish()) {
Expand Down

0 comments on commit 09897b6

Please sign in to comment.