Skip to content

Stabilize flows #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 4, 2022
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
Fix: show working workspaces
- finer grained error handling when resolving agents
- resolves #51
  • Loading branch information
fioan89 committed Aug 3, 2022
commit 582b789e03ebdf3a5676c78d5124ef0ce53ef400
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [Unreleased]
### Fixed
- `Recent Coder Workspaces` label overlaps with the search bar in the `Connections` view
- working Workspaces are now listed when there are issues with resolving agents

### Changed
- links to documentation now point to the latest Coder OSS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.coder.gateway.sdk.Arch
import com.coder.gateway.sdk.CoderRestClientService
import com.coder.gateway.sdk.OS
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
import com.coder.gateway.sdk.v2.models.Workspace
import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
import com.intellij.ide.IdeBundle
import com.intellij.openapi.Disposable
Expand Down Expand Up @@ -87,23 +88,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
cs.launch {
val workspaceList = withContext(Dispatchers.IO) {
try {
val workspaces = coderClient.workspaces()
return@withContext workspaces.flatMap { workspace ->
val agents = coderClient.workspaceAgents(workspace)
val shouldContainAgentName = agents.size > 1
agents.map { agent ->
val workspaceName = if (shouldContainAgentName) "${workspace.name}.${agent.name}" else workspace.name
WorkspaceAgentModel(
workspaceName,
workspace.templateName,
workspace.latestBuild.job.status,
workspace.latestBuild.workspaceTransition,
OS.from(agent.operatingSystem),
Arch.from(agent.architecture),
agent.directory
)
}
}
return@withContext coderClient.workspaces().collectAgents()
} catch (e: Exception) {
logger.error("Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL}. Reason: $e")
emptyList()
Expand All @@ -115,6 +100,30 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
}
}

private fun List<Workspace>.collectAgents(): List<WorkspaceAgentModel> {
return this.flatMap { workspace ->
try {
val agents = coderClient.workspaceAgents(workspace)
val shouldContainAgentName = agents.size > 1
return@flatMap agents.map { agent ->
val workspaceName = if (shouldContainAgentName) "${workspace.name}.${agent.name}" else workspace.name
WorkspaceAgentModel(
workspaceName,
workspace.templateName,
workspace.latestBuild.job.status,
workspace.latestBuild.workspaceTransition,
OS.from(agent.operatingSystem),
Arch.from(agent.architecture),
agent.directory
)
}
} catch (e: Exception) {
logger.error("Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e")
emptyList()
}
}
}

override fun onNext(wizardModel: CoderWorkspacesWizardModel): Boolean {
val workspace = tableOfWorkspaces.selectedObject
if (workspace != null) {
Expand Down