@@ -64,6 +64,7 @@ import kotlinx.coroutines.cancel
64
64
import kotlinx.coroutines.delay
65
65
import kotlinx.coroutines.isActive
66
66
import kotlinx.coroutines.launch
67
+ import kotlinx.coroutines.runBlocking
67
68
import kotlinx.coroutines.withContext
68
69
import org.zeroturnaround.exec.ProcessExecutor
69
70
import java.awt.Component
@@ -399,12 +400,20 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
399
400
400
401
val authTask = object : Task .Modal (null , CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.cli.downloader.dialog.title" ), false ) {
401
402
override fun run (pi : ProgressIndicator ) {
402
-
403
403
pi.apply {
404
404
isIndeterminate = false
405
- text = " Downloading coder cli ..."
405
+ text = " Retrieving Workspaces ..."
406
406
fraction = 0.1
407
407
}
408
+ runBlocking {
409
+ loadWorkspaces()
410
+ }
411
+
412
+ pi.apply {
413
+ isIndeterminate = false
414
+ text = " Downloading Coder CLI..."
415
+ fraction = 0.3
416
+ }
408
417
409
418
cliManager.downloadCLI()
410
419
if (getOS() != OS .WINDOWS ) {
@@ -413,7 +422,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
413
422
logger.info(" chmod +x ${cliManager.localCli.toAbsolutePath()} $chmodOutput " )
414
423
}
415
424
pi.apply {
416
- text = " Configuring coder cli ..."
425
+ text = " Configuring Coder CLI ..."
417
426
fraction = 0.5
418
427
}
419
428
@@ -424,7 +433,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
424
433
logger.info(" Result of `${localWizardModel.localCliPath} config-ssh --yes --use-previous-options`: $sshConfigOutput " )
425
434
426
435
pi.apply {
427
- text = " Remove old coder cli versions..."
436
+ text = " Remove old Coder CLI versions..."
428
437
fraction = 0.9
429
438
}
430
439
cliManager.removeOldCli()
@@ -467,35 +476,50 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
467
476
468
477
poller = cs.launch {
469
478
while (isActive) {
470
- loadWorkspaces()
471
479
delay(5000 )
480
+ loadWorkspaces()
472
481
}
473
482
}
474
483
}
475
484
476
485
private suspend fun loadWorkspaces () {
477
- val workspaceList = withContext(Dispatchers .IO ) {
486
+ withContext(Dispatchers .IO ) {
487
+ val timeBeforeRequestingWorkspaces = System .currentTimeMillis()
478
488
try {
479
- return @withContext coderClient.workspaces().collectAgents()
489
+ val ws = coderClient.workspaces()
490
+ val timeAfterRequestingWorkspaces = System .currentTimeMillis()
491
+ logger.info(" Retrieving the workspaces took: ${timeAfterRequestingWorkspaces - timeBeforeRequestingWorkspaces} millis" )
492
+ ws.resolveAndDisplayAgents()
480
493
} catch (e: Exception ) {
481
494
logger.error(" Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL} . Reason: $e " )
482
- emptyList()
483
495
}
484
496
}
497
+ }
485
498
486
- withContext(Dispatchers .Main ) {
487
- val selectedWorkspace = tableOfWorkspaces.selectedObject?.name
488
- listTableModelOfWorkspaces.items = workspaceList
489
- if (selectedWorkspace != null ) {
490
- tableOfWorkspaces.selectItem(selectedWorkspace)
499
+ private fun List<Workspace>.resolveAndDisplayAgents () {
500
+ this .forEach { workspace ->
501
+ cs.launch(Dispatchers .IO ) {
502
+ val timeBeforeRequestingAgents = System .currentTimeMillis()
503
+ workspace.agentModels().forEach { am ->
504
+ withContext(Dispatchers .Main ) {
505
+ val selectedWorkspace = tableOfWorkspaces.selectedObject?.name
506
+ if (listTableModelOfWorkspaces.indexOf(am) >= 0 ) {
507
+ val index = listTableModelOfWorkspaces.indexOf(am)
508
+ listTableModelOfWorkspaces.setItem(index, am)
509
+ } else {
510
+ listTableModelOfWorkspaces.addRow(am)
511
+ }
512
+ if (selectedWorkspace != null ) {
513
+ tableOfWorkspaces.selectItem(selectedWorkspace)
514
+ }
515
+ }
516
+ }
517
+ val timeAfterRequestingAgents = System .currentTimeMillis()
518
+ logger.info(" Retrieving the agents for ${workspace.name} took: ${timeAfterRequestingAgents - timeBeforeRequestingAgents} millis" )
491
519
}
492
520
}
493
521
}
494
522
495
- private fun List<Workspace>.collectAgents (): List <WorkspaceAgentModel > {
496
- return this .flatMap { it.agentModels() }.toList()
497
- }
498
-
499
523
private fun Workspace.agentModels (): List <WorkspaceAgentModel > {
500
524
return try {
501
525
val agents = coderClient.workspaceAgentsByTemplate(this )
0 commit comments