Skip to content

Commit

Permalink
Implement gp tasks stop --force-success (#20067)
Browse files Browse the repository at this point in the history
* Implement `gp tasks stop --force-success`

* Fix potential race
  • Loading branch information
filiptronicek authored Jul 26, 2024
1 parent 519b678 commit a4c1a31
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 224 deletions.
6 changes: 4 additions & 2 deletions components/gitpod-cli/cmd/tasks-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
)

var stopTaskCmdOpts struct {
All bool
All bool
ForceSuccess bool
}

// stopTaskCmd represents the stop task command
Expand Down Expand Up @@ -113,7 +114,7 @@ var stopTaskCmd = &cobra.Command{
}

for _, terminalAlias := range terminalAliases {
_, err = client.Terminal.Shutdown(ctx, &api.ShutdownTerminalRequest{Alias: terminalAlias})
_, err = client.Terminal.Shutdown(ctx, &api.ShutdownTerminalRequest{Alias: terminalAlias, ForceSuccess: stopTaskCmdOpts.ForceSuccess})
if err != nil {
return xerrors.Errorf("cannot stop task: %w", err)
}
Expand All @@ -126,4 +127,5 @@ func init() {
tasksCmd.AddCommand(stopTaskCmd)

stopTaskCmd.Flags().BoolVarP(&stopTaskCmdOpts.All, "all", "a", false, "stop all tasks")
stopTaskCmd.Flags().BoolVarP(&stopTaskCmdOpts.ForceSuccess, "force-success", "f", false, "force the task to exit with status code 0")
}
320 changes: 165 additions & 155 deletions components/supervisor-api/go/terminal.pb.go

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion components/supervisor-api/go/terminal.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/supervisor-api/terminal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ message OpenTerminalResponse {

message ShutdownTerminalRequest {
string alias = 1;
bool force_success = 2;
}
message ShutdownTerminalResponse {}

Expand Down
6 changes: 5 additions & 1 deletion components/supervisor/pkg/supervisor/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ func (tm *tasksManager) Run(ctx context.Context, wg *sync.WaitGroup, successChan
taskLog.Info("task terminal has been closed. Waiting for watch() to finish...")
taskWatchWg.Wait()
taskLog.Info("watch() has finished, setting task state to closed")
if state != nil {

if term.ForceSuccess {
// Simulate state.Success()
t.successChan <- taskSuccessful
} else if state != nil {
if state.Success() {
t.successChan <- taskSuccessful
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/pkg/terminal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (srv *MuxTerminalService) OpenWithOptions(ctx context.Context, req *api.Ope

// Close closes a terminal for the given alias.
func (srv *MuxTerminalService) Shutdown(ctx context.Context, req *api.ShutdownTerminalRequest) (*api.ShutdownTerminalResponse, error) {
err := srv.Mux.CloseTerminal(ctx, req.Alias)
err := srv.Mux.CloseTerminal(ctx, req.Alias, req.ForceSuccess)
if err == ErrNotFound {
return nil, status.Error(codes.NotFound, err.Error())
}
Expand Down
Loading

0 comments on commit a4c1a31

Please sign in to comment.