Skip to content

Commit a79aa64

Browse files
authored
fix: Use cliui.WorkspaceBuild to prevent cancel of builds jobs (#1255)
Build jobs cannot gracefully terminate because Terraform generally cannot gracefully terminate.
1 parent 7534328 commit a79aa64

File tree

3 files changed

+3
-41
lines changed

3 files changed

+3
-41
lines changed

cli/server.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,7 @@ func server() *cobra.Command {
361361
return xerrors.Errorf("delete workspace: %w", err)
362362
}
363363

364-
err = cliui.ProvisionerJob(cmd.Context(), cmd.OutOrStdout(), cliui.ProvisionerJobOptions{
365-
Fetch: func() (codersdk.ProvisionerJob, error) {
366-
build, err := client.WorkspaceBuild(cmd.Context(), build.ID)
367-
return build.Job, err
368-
},
369-
Cancel: func() error {
370-
return client.CancelWorkspaceBuild(cmd.Context(), build.ID)
371-
},
372-
Logs: func() (<-chan codersdk.ProvisionerJobLog, error) {
373-
return client.WorkspaceBuildLogsAfter(cmd.Context(), build.ID, before)
374-
},
375-
})
364+
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
376365
if err != nil {
377366
return xerrors.Errorf("delete workspace %s: %w", workspace.Name, err)
378367
}

cli/workspacestart.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,7 @@ func workspaceStart() *cobra.Command {
3535
if err != nil {
3636
return err
3737
}
38-
err = cliui.ProvisionerJob(cmd.Context(), cmd.OutOrStdout(), cliui.ProvisionerJobOptions{
39-
Fetch: func() (codersdk.ProvisionerJob, error) {
40-
build, err := client.WorkspaceBuild(cmd.Context(), build.ID)
41-
return build.Job, err
42-
},
43-
Cancel: func() error {
44-
return client.CancelWorkspaceBuild(cmd.Context(), build.ID)
45-
},
46-
Logs: func() (<-chan codersdk.ProvisionerJobLog, error) {
47-
return client.WorkspaceBuildLogsAfter(cmd.Context(), build.ID, before)
48-
},
49-
})
50-
return err
38+
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
5139
},
5240
}
5341
}

cli/workspacestop.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,7 @@ func workspaceStop() *cobra.Command {
3535
if err != nil {
3636
return err
3737
}
38-
err = cliui.ProvisionerJob(cmd.Context(), cmd.OutOrStdout(), cliui.ProvisionerJobOptions{
39-
Fetch: func() (codersdk.ProvisionerJob, error) {
40-
build, err := client.WorkspaceBuild(cmd.Context(), build.ID)
41-
return build.Job, err
42-
},
43-
Cancel: func() error {
44-
return client.CancelWorkspaceBuild(cmd.Context(), build.ID)
45-
},
46-
Logs: func() (<-chan codersdk.ProvisionerJobLog, error) {
47-
return client.WorkspaceBuildLogsAfter(cmd.Context(), build.ID, before)
48-
},
49-
})
50-
if err != nil {
51-
return err
52-
}
53-
return nil
38+
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
5439
},
5540
}
5641
}

0 commit comments

Comments
 (0)