Skip to content

Commit

Permalink
feat: task失败可以立即重试 TencentBlueKing#6400
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzcao committed Mar 28, 2022
1 parent 7062938 commit e5006d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ object ModelUtils {
val jobStatus = BuildStatus.parse(c.status)
c.canRetry = jobStatus.isFailure() || jobStatus.isCancel()
}

val failElements = mutableListOf<Element>()
c.elements.forEach { e ->
refreshElement(element = e, failElements = failElements)
if (c.canRetry == true) {
val failElements = mutableListOf<Element>()
c.elements.forEach { e ->
refreshElement(element = e, failElements = failElements)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ object ProcessMessageCode {
const val ERROR_TIMEOUT_IN_BUILD_QUEUE = "2101904" // 排队超时,取消运行! [{0}]
const val ERROR_PARUS_PIEPLINE_IS_RUNNINT = "2101905" // 暂停的流水线已开始运行
const val ERROR_ELEMENT_TOO_LONG = "2101906" // {0} element大小越界
const val ERROR_STOP_VM_UN_FINISH = "2101907" // stopVm还未完成,请稍后重试
const val ERROR_JOB_RUNNING = "2101907" // job非完成态,不能进行重试

const val ERROR_NO_BUILD_EXISTS_BY_ID = "2101100" // 流水线构建[{0}]不存在
const val ERROR_NO_PIPELINE_EXISTS_BY_ID = "2101101" // 流水线[{0}]不存在
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class PipelineInfoDao {
fun listByProject(dslContext: DSLContext, projectCode: String): Result<Record2<String, Long>> {
return with(T_PIPELINE_INFO) {
dslContext.select(PIPELINE_ID.`as`("pipelineId"), ID.`as`("id")).from(this)
.where(PROJECT_ID.eq(projectCode)).fetch()
.where(PROJECT_ID.eq(projectCode).and(DELETE.eq(false))).fetch()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatch
import com.tencent.devops.common.event.enums.ActionType
import com.tencent.devops.common.log.utils.BuildLogPrinter
import com.tencent.devops.common.pipeline.enums.BuildStatus
import com.tencent.devops.common.service.utils.MessageCodeUtil
import com.tencent.devops.process.constant.ProcessMessageCode
import com.tencent.devops.process.engine.common.VMUtils
import com.tencent.devops.process.engine.pojo.PipelineBuildContainer
Expand Down Expand Up @@ -122,33 +123,17 @@ class PipelineRetryFacadeService @Autowired constructor(
)
}

// 若当前job的关机任务还未完成,报错让用户稍后再重试。否则会因为开机比关机早到引发引擎调度问题
// 若当前job状态还未完成,报错让用户稍后再重试。否则会因为开机比关机早到引发引擎调度问题
private fun checkStopTask(
projectId: String,
buildId: String,
containerInfo: PipelineBuildContainer
) {
var jobFinish = true
if (!containerInfo.status.isFinish()) {
val runningTasks = pipelineTaskService.listContainerBuildTasks(
projectId = projectId,
buildId = buildId,
containerSeqId = containerInfo.containerId,
buildStatusSet = setOf(BuildStatus.RUNNING)
)
runningTasks.forEach {
if (it.taskId.startsWith(VMUtils.getStopVmLabel()) || it.taskId.startsWith(VMUtils.getEndLabel())) {
jobFinish = false
return@forEach
}
}
}

if (!jobFinish) {
logger.warn("retry runningJob: $projectId|$buildId stopVm not finish")
logger.warn("retry runningJob: $projectId|$buildId${containerInfo.containerId} is running")
throw ErrorCodeException(
errorCode = ProcessMessageCode.ERROR_STOP_VM_UN_FINISH,
defaultMessage = "$buildId${containerInfo.containerId} stopVm未完成,请稍后重试"
errorCode = ProcessMessageCode.ERROR_JOB_RUNNING,
defaultMessage = MessageCodeUtil.getCodeLanMessage(ProcessMessageCode.ERROR_JOB_RUNNING)
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion support-files/sql/5001_ci_project-init_dml_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESS
REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('b6d9420993954802884f474828cc0db1', '2101904', '01', '流水线:排队超时,取消运行! [{0}]', 'Pipeline: Queue timed out, canceled running! [{0}]');
REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('7d8f2d20b939448f91550967d5ff63b6', '2101905', '01', '流水线:暂停的流水线已开始运行', 'Pipeline: Pipeline: puase pipeline running now');
REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('4e6d9a9c3c874c16b2fcff32b6a731fd', '2101906', '01', '流水线:{0} element大小越界', 'Pipeline: Pipeline: {0} element size too long');
REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('894102da867c431baf9fca6bfd6bc640', '2101907', '01', '流水线: stopVm还未完成,请稍后重试', 'Pipeline: stopVm running, please wait...');
REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('894102da867c431baf9fca6bfd6bc640', '2101907', '01', '流水线: job非完成态,不能进行重试', 'Pipeline: job is running, forbid retry');


REPLACE INTO `T_MESSAGE_CODE_DETAIL` (`ID`, `MESSAGE_CODE`, `MODULE_CODE`, `MESSAGE_DETAIL_ZH_CN`, `MESSAGE_DETAIL_EN`) VALUES ('a1d8bb8bc3e54b0daaf6d22daef17650', '2101908', '01', '流水线:质量红线(准入)配置有误:Fail to find quality gate intercept element', 'Pipeline: The quality red line (access) is incorrectly configured: Fail to find quality gate intercept element');
Expand Down

0 comments on commit e5006d2

Please sign in to comment.