Skip to content

fix(scaletest): cleanup: attempt to cancel in-progress jobs #9080

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 2 commits into from
Aug 14, 2023
Merged
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
refactor
  • Loading branch information
johnstcn committed Aug 14, 2023
commit 91b35293b5917f0b77c1f259acc2eef99dfcf600
21 changes: 7 additions & 14 deletions scaletest/workspacebuild/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,18 @@ func (r *CleanupRunner) Run(ctx context.Context, _ string, logs io.Writer) error
}

build, err := r.client.WorkspaceBuild(ctx, ws.LatestBuild.ID)
var canceled bool
if err == nil {
if build.Job.Status.Active() {
// mark the build as canceled
if err = r.client.CancelWorkspaceBuild(ctx, build.ID); err != nil {
logger.Warn(ctx, "failed to cancel workspace build, attempting to delete anyway", slog.Error(err))
} else {
canceled = true
}
if err == nil && build.Job.Status.Active() {
// mark the build as canceled
if err = r.client.CancelWorkspaceBuild(ctx, build.ID); err == nil {
// Wait for the job to cancel before we delete it
_ = waitForBuild(ctx, logs, r.client, build.ID) // it will return a "build canceled" error
} else {
logger.Warn(ctx, "failed to cancel workspace build, attempting to delete anyway", slog.Error(err))
}
} else {
logger.Warn(ctx, "unable to lookup latest workspace build, attempting to delete anyway", slog.Error(err))
}

if canceled {
// Wait for the job to cancel before we delete it
_ = waitForBuild(ctx, logs, r.client, build.ID) // it will return a "build canceled" error
}

build, err = r.client.CreateWorkspaceBuild(ctx, r.workspaceID, codersdk.CreateWorkspaceBuildRequest{
Transition: codersdk.WorkspaceTransitionDelete,
})
Expand Down