Skip to content

Commit

Permalink
Refactor Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed Feb 25, 2021
1 parent 1934e15 commit 1b49dfe
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Agent(
}.apply {
ponger(outgoing)

println("\nAgent connected")
launch {
for (frame in incoming) {
when (frame) {
Expand All @@ -69,7 +68,7 @@ class Agent(
}

private fun textFrameHandler(frame: Frame.Text) {
println("Received: ${frame.readText()}")
println("\nReceived: ${frame.readText()}")
val result = format.decodeFromString<CommandResult>(frame.readText())
tasks[result.id]?.let { it(result) }
}
Expand All @@ -85,21 +84,23 @@ class Agent(
)
)
tasks[id] = getCommonHandler(task)
task.join()
withTimeout(20_000) {
task.join()
}
}

suspend fun waitForAgentReady() = withProgress {
var ready: Boolean
var booting: Boolean
do {
delay(20_000)
ready = try {
booting = try {
connect()
isReady()
false
} catch (ex: Exception) {
true
}
} while (ready)
} while (booting)
}

suspend fun uploadFile(path: String, bytes: ByteArray) {
Expand Down

0 comments on commit 1b49dfe

Please sign in to comment.