Skip to content

Commit

Permalink
优化日志打印与提示。
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Feb 26, 2021
1 parent 09dfb79 commit 7c4fb13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions src/main/kotlin/com/tencent/bk/devops/atom/task/InnerJobAtom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ class InnerJobAtom : TaskAtom<InnerJobParam> {
taskInstanceId = taskInstanceId,
operator = operator,
buildId = buildId,
esbHost = esbHost
esbHost = esbHost,
result = result
)

logger.info(JobUtils.getDetailUrl(jobHost, bizId, taskInstanceId))
Expand All @@ -287,33 +288,43 @@ class InnerJobAtom : TaskAtom<InnerJobParam> {
operator: String,
buildId: String,
taskId: String,
esbHost: String
esbHost: String,
result: AtomResult
) {
logger.info("begin to check task status")
if (System.currentTimeMillis() - startTime > maxRunningMills) {
logger.warn("job getTimeout. getTimeout minutes:${maxRunningMills / 60000}")
throw RuntimeException("job Timeout, executeTime:${System.currentTimeMillis() - startTime}")
}

var jobSuccess = true
var needContinue = true

while (jobSuccess) {
while (needContinue) {
Thread.sleep(5000)
logger.info(JobUtils.getDetailUrl(jobHost, bizId, taskInstanceId))
val taskResult = JobUtils.getTaskResult(appId, appSecret, bizId, taskInstanceId, operator, esbHost)
if (taskResult.isFinish) {
needContinue = false
if (taskResult.success) {
logger.info("[$buildId]|SUCCEED|taskInstanceId=$taskId|${taskResult.msg}")
jobSuccess = false
} else {
logger.info("[$buildId]|FAIL|taskInstanceId=$taskId|${taskResult.msg}")
throw RuntimeException("job execute fail, message:${taskResult.msg}")
val msg = "job execute fail, message:${taskResult.msg}"
result.status = Status.failure
result.message =
"${msg}文件分发失败,请根据使用的蓝鲸版本点击插件日志中对应的链接前往作业平台查看详情(Push file fail, please click the link and go to Job to check the detail.)"
}
} else {
logger.info("执行中/Waiting for job:$taskInstanceId", taskId)
}

if (System.currentTimeMillis() - startTime > maxRunningMills) {
needContinue = false
logger.error("job execute timeout, exit out")
throw RuntimeException("job Timeout, executeTime:${System.currentTimeMillis() - startTime}")
val msg = "job Timeout, executeTime:${System.currentTimeMillis() - startTime}"
result.status = Status.failure
result.message =
"${msg}文件分发失败,请根据使用的蓝鲸版本点击插件日志中对应的链接前往作业平台查看详情(Push file fail, please click the link and go to Job to check the detail.)"
}
}
logger.info("Job执行耗时(Time consuming):${System.currentTimeMillis() - startTime}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ object JobUtils {
}

fun getDetailUrl(jobHost: String, appId: String, taskInstanceId: Long): String {
return "<a target='_blank' href='$jobHost/?taskInstanceList&appId=$appId#taskInstanceId=$taskInstanceId'>查看详情(Go to Detail)</a>"
return "<a target='_blank' href='$jobHost/?taskInstanceList&appId=$appId#taskInstanceId=$taskInstanceId'>到作业平台V2查看详情(Go to JobV2 for Detail, click this if using BlueKing5.x)</a> <a target='_blank' href='$jobHost/api_execute/$taskInstanceId'>到作业平台V3查看详情(Go to JobV3 for Detail, click this if using BlueKing6.x)</a>"
}
}
}

0 comments on commit 7c4fb13

Please sign in to comment.