Skip to content

Make "start" dialog check for workspace latest uild status before sending restart. #355

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 7 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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