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 546e080 commit 5db59b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/main/kotlin/com/tencent/bk/devops/atom/task/JobScriptAtom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,20 @@ class JobScriptAtom : TaskAtom<InnerJobParam> {

try {
val taskInstanceId = JobUtils.fastExecuteScript(fastExecuteScriptReq, this.esbApiHost)
logger.info(JobUtils.getDetailUrl(bizId, taskInstanceId, jobHost))
val startTime = System.currentTimeMillis()

checkStatus(
bizId = bizId,
startTime = startTime,
taskId = taskId,
taskInstanceId = taskInstanceId,
operator = operator,
buildId = buildId,
jobHost = esbApiHost
jobHost = esbApiHost,
result = result
)

logger.info(JobUtils.getDetailUrl(bizId, taskInstanceId, jobHost))
result.status = Status.success
} catch (e: Exception) {
logger.error("Job API invoke failed", e)
result.status = Status.failure
Expand All @@ -151,21 +151,26 @@ class JobScriptAtom : TaskAtom<InnerJobParam> {
operator: String,
buildId: String,
taskId: String,
jobHost: String
jobHost: String,
result: AtomResult
) {

var jobSuccess = true
var needContinue = true

while (jobSuccess) {
while (needContinue) {
Thread.sleep(2000)
val taskResult = JobUtils.getTaskResult(appId, appSecret, bizId, taskInstanceId, operator, jobHost)
logger.info(JobUtils.getDetailUrl(bizId, taskInstanceId, jobHost))
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, mssage:${taskResult.msg}")
logger.info("脚本本身执行失败(Script failure):${taskResult.msg}")
result.status = Status.failure
result.message =
"脚本执行失败,请根据使用的蓝鲸版本点击插件日志中对应的链接前往作业平台查看脚本失败详情,作业平台以脚本最后一条语句的返回码为0来判断脚本为执行成功状态,请检查脚本本身业务逻辑,若为脚本执行超时失败,请检查脚本自身逻辑有无死循环或耗时操作,若正常逻辑耗时较长请调整插件的超时参数(默认1000s)(Script fail, please click the link and go to Job to check the detail of script failure, Job judges that the script is executed successfully by the return code of the last line of the script as 0. Please check the content of script. If script fail because of timeout, please check whether there is a dead loop or long-time operation in script content. If the normal business logic requires long time, please adjust the timeout parameter of this plugin.)"
}
} else {
logger.info("执行中/Waiting for job:$taskInstanceId", taskId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.tencent.bk.devops.atom.task.utils

import com.tencent.bk.devops.atom.task.pojo.FastExecuteScriptRequest
Expand All @@ -24,6 +23,6 @@ object JobUtils {
}

fun getDetailUrl(appId: String, taskInstanceId: Long, jobHost: String): String {
return "<a target='_blank' href='$jobHost/?taskInstanceList&appId=$appId#taskInstanceId=$taskInstanceId'>查看详情(Go to Job for 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>"
}
}
10 changes: 10 additions & 0 deletions task.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
"hidden": false,
"isSensitive": false
},
"tipsNotDel": {
"type": "tips",
"label": "",
"tipStr": "请勿删除脚本模板首行内容,可在脚本末尾处编写您的业务代码,建议在脚本首尾及关键分支位置打印日志(Please do not delete the first line of script template. You can add your script content to the end of the script template. Logging at the start, end and key point of script is recommended.)"
},
"tipsFailHandle": {
"type": "tips",
"label": "",
"tipStr": "若执行失败,请根据使用的蓝鲸版本点击插件日志中对应的链接前往作业平台查看脚本失败详情,若为脚本执行超时失败,请检查脚本自身逻辑有无死循环或耗时操作,若正常逻辑耗时较长请调整插件的超时参数(If script fail, please click the link in the log and go to Job to check the detail of script failure. If script fail because of timeout, please check whether there is a dead loop or long-time operation in script content. If the normal business logic requires long time, please adjust the timeout parameter of this plugin.)"
},
"scriptContent": {
"label": "脚本内容(Script Content)",
"default": "",
Expand Down

0 comments on commit 5db59b8

Please sign in to comment.