Skip to content

Commit

Permalink
Make "start" dialog check for workspace latest uild status before sen…
Browse files Browse the repository at this point in the history
…ding restart. (#355)
  • Loading branch information
bcpeinhardt authored Sep 9, 2024
1 parent c6e7f36 commit 8293ce9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

- Previously, if a workspace stopped or restarted causing the "Start" dialog to
appear in VS Code, the start button would fire a start workspace request regardless
of the workspace status.
Now we perform a check to see if the workspace is still stopped or failed. If its status
has changed out from under the IDE, it will not fire a redundant start request.

### Changed

- Previously, the extension would always log SSH proxy diagnostics to a fixed
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ was but for now it means some things are difficult to test as you cannot import

## Development

> [!IMPORTANT]
> Reasoning about networking gets really wonky trying to develop
> this extension from a coder workspace. We currently recommend cloning the
> repo locally
1. Run `yarn watch` in the background.
2. OPTIONAL: Compile the `coder` binary and place it in the equivalent of
`os.tmpdir() + "/coder"`. If this is missing, it will download the binary
Expand Down
15 changes: 12 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function makeCoderSdk(baseUrl: string, token: string | undefined, s
/**
* Start or update a workspace and return the updated workspace.
*/
export async function startWorkspace(restClient: Api, workspace: Workspace): Promise<Workspace> {
export async function startWorkspaceIfStoppedOrFailed(restClient: Api, workspace: Workspace): Promise<Workspace> {
// If the workspace requires the latest active template version, we should attempt
// to update that here.
// TODO: If param set changes, what do we do??
Expand All @@ -103,9 +103,18 @@ export async function startWorkspace(restClient: Api, workspace: Workspace): Pro
workspace.template_active_version_id
: // Default to not updating the workspace if not required.
workspace.latest_build.template_version_id
const latestBuild = await restClient.startWorkspace(workspace.id, versionID)

// Before we start a workspace, we make an initial request to check it's not already started
const updatedWorkspace = await restClient.getWorkspace(workspace.id)

if (!["stopped", "failed"].includes(updatedWorkspace.latest_build.status)) {
return updatedWorkspace
}

const latestBuild = await restClient.startWorkspace(updatedWorkspace.id, versionID)

return {
...workspace,
...updatedWorkspace,
latest_build: latestBuild,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from "path"
import prettyBytes from "pretty-bytes"
import * as semver from "semver"
import * as vscode from "vscode"
import { makeCoderSdk, startWorkspace, waitForBuild } from "./api"
import { makeCoderSdk, startWorkspaceIfStoppedOrFailed, waitForBuild } from "./api"
import { extractAgents } from "./api-helper"
import * as cli from "./cliManager"
import { Commands } from "./commands"
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Remote {
return undefined
}
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
workspace = await startWorkspace(restClient, workspace)
workspace = await startWorkspaceIfStoppedOrFailed(restClient, workspace)
break
case "failed":
// On a first attempt, we will try starting a failed workspace
Expand All @@ -115,7 +115,7 @@ export class Remote {
return undefined
}
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
workspace = await startWorkspace(restClient, workspace)
workspace = await startWorkspaceIfStoppedOrFailed(restClient, workspace)
break
}
// Otherwise fall through and error.
Expand Down

0 comments on commit 8293ce9

Please sign in to comment.