Skip to content

Commit

Permalink
feat: 完善用户取消与系统强制终止的状态区别 #4420
Browse files Browse the repository at this point in the history
提高短时任务获取任务的频率,长时获取频率保持不变
  • Loading branch information
irwinsun committed Jun 15, 2021
1 parent 7a05867 commit 6203794
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

package com.tencent.devops.agent

const val AGENT_VERSION = 12.31 // 此处不能以0结束
const val AGENT_VERSION = 12.35 // 此处不能以0结束

fun main() {
println(AGENT_VERSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import kotlin.system.exitProcess

object Runner {

private const val maxSleepStep = 50L
private const val windows = 5L
private const val millsStep = 100L
private val logger = LoggerFactory.getLogger(Runner::class.java)

fun run(workspaceInterface: WorkspaceInterface, systemExit: Boolean = true) {
Expand Down Expand Up @@ -131,6 +134,7 @@ object Runner {
LoggerService.addNormalLine("Start the runner at workspace(${workspacePathFile.absolutePath})")
logger.info("Start the runner at workspace(${workspacePathFile.absolutePath})")

var waitCount = 0
loop@ while (true) {
logger.info("Start to claim the task")
val buildTask = EngineService.claimTask()
Expand All @@ -156,15 +160,24 @@ object Runner {
val buildTaskRst = taskDaemon.getBuildResult()
EngineService.completeTask(buildTaskRst)
logger.info("Finish completing the task ($buildTask)")
} catch (exception: Throwable) {
} catch (ignore: Throwable) {
failed = true
dealException(exception, buildTask, taskDaemon)
dealException(ignore, buildTask, taskDaemon)
} finally {
LoggerService.finishTask()
LoggerService.elementId = ""
waitCount = 0
}
}
BuildTaskStatus.WAIT -> Thread.sleep(5000)
BuildTaskStatus.WAIT -> {
var sleepStep = waitCount++ / windows
if (sleepStep <= 0) {
sleepStep = 1
}
val sleepMills = sleepStep.coerceAtMost(maxSleepStep) * millsStep
logger.info("WAIT $sleepMills ms")
Thread.sleep(sleepMills)
}
BuildTaskStatus.END -> break@loop
}
}
Expand All @@ -191,8 +204,8 @@ object Runner {
if (!file.deleteRecursively()) {
logger.warn("Fail to clean up the workspace")
}
} catch (e: Exception) {
logger.error("Fail to clean up the workspace.", e)
} catch (ignore: Exception) {
logger.error("Fail to clean up the workspace.", ignore)
}
}
}
Expand Down

0 comments on commit 6203794

Please sign in to comment.