Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
impl: improved poll job lifecycle report
Poll jobs now have a random friendly name that changes each time
a new job is created, and the logging for when the jobs are created
or cancelled is also improved. The idea behind this commit is to improve
debugging sessions on client logs by:
- having clear log lines saying when a job is created/destructed
- easy to remember and cross-match job names (instead of cryptic java reference values)
  • Loading branch information
fioan89 committed Sep 12, 2025
commit 6aa83fd42daf4a9231f8d9581f336fc089567b10
14 changes: 10 additions & 4 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.coder.toolbox.sdk.ex.APIResponseException
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
import com.coder.toolbox.util.CoderProtocolHandler
import com.coder.toolbox.util.DialogUi
import com.coder.toolbox.util.friendlyName
import com.coder.toolbox.util.name
import com.coder.toolbox.util.toURL
import com.coder.toolbox.util.waitForTrue
import com.coder.toolbox.util.withPath
Expand Down Expand Up @@ -89,7 +91,7 @@ class CoderRemoteProvider(
* first time).
*/
private fun poll(client: CoderRestClient, cli: CoderCLIManager): Job =
context.cs.launch(CoroutineName("Workspace Poller")) {
context.cs.launch(CoroutineName("Workspace Poller - ${friendlyName()}")) {
var lastPollTime = TimeSource.Monotonic.markNow()
while (isActive) {
try {
Expand Down Expand Up @@ -242,7 +244,10 @@ class CoderRemoteProvider(
* Also called as part of our own logout.
*/
override fun close() {
pollJob?.cancel()
pollJob?.let {
it.cancel()
context.logger.info("Cancelled workspace poll job ${pollJob.name()}")
}
client?.close()
lastEnvironments.clear()
environments.value = LoadableState.Value(emptyList())
Expand Down Expand Up @@ -327,6 +332,7 @@ class CoderRemoteProvider(

environments.showLoadingMessage()
pollJob = poll(restClient, cli)
context.logger.info("Workspace poll job with name ${pollJob.name()} was created while handling URI $uri")
isInitialized.waitForTrue()
}
} catch (ex: Exception) {
Expand Down Expand Up @@ -406,13 +412,13 @@ class CoderRemoteProvider(
this.client = client
pollJob?.let {
it.cancel()
context.logger.info("Workspace poll job with reference ${pollJob} was canceled")
context.logger.info("Cancelled workspace poll job ${pollJob.name()} in order to start a new one")
}
environments.showLoadingMessage()
coderHeaderPage.setTitle(context.i18n.pnotr(client.url.toString()))
context.logger.info("Displaying ${client.url} in the UI")
pollJob = poll(client, cli)
context.logger.info("Workspace poll job created with reference $pollJob")
context.logger.info("Workspace poll job with name ${pollJob.name()} was created")
}

private fun MutableStateFlow<LoadableState<List<CoderRemoteEnvironment>>>.showLoadingMessage() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/coder/toolbox/util/CoroutineExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.coder.toolbox.util

import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.Job

fun Job?.name(): String = this?.get(CoroutineName)?.toString() ?: this.toString()
25 changes: 25 additions & 0 deletions src/main/kotlin/com/coder/toolbox/util/NameGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.coder.toolbox.util

import kotlin.random.Random

val adjectives = listOf(
"brave", "calm", "clever", "curious", "eager",
"fast", "gentle", "happy", "kind", "lively",
"mighty", "noble", "quiet", "rapid", "shiny",
"swift", "tough", "vast", "wise", "young"
)

val nouns = listOf(
"bear", "cloud", "dragon", "eagle", "fire",
"forest", "hawk", "lion", "moon", "mountain",
"owl", "panther", "river", "shadow", "sky",
"star", "storm", "tree", "wolf", "wind"
)

/**
* Easy to remember names, helps with logs investigation
*/
fun friendlyName(): String {
val number = Random.nextInt(10, 99) // 2 digits for extra uniqueness
return "${adjectives.random()}-${nouns.random()}-$number"
}
Loading