Skip to content

Commit a4c1a31

Browse files
Implement gp tasks stop --force-success (#20067)
* Implement `gp tasks stop --force-success` * Fix potential race
1 parent 519b678 commit a4c1a31

File tree

8 files changed

+338
-224
lines changed

8 files changed

+338
-224
lines changed

components/gitpod-cli/cmd/tasks-stop.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
)
1919

2020
var stopTaskCmdOpts struct {
21-
All bool
21+
All bool
22+
ForceSuccess bool
2223
}
2324

2425
// stopTaskCmd represents the stop task command
@@ -113,7 +114,7 @@ var stopTaskCmd = &cobra.Command{
113114
}
114115

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

128129
stopTaskCmd.Flags().BoolVarP(&stopTaskCmdOpts.All, "all", "a", false, "stop all tasks")
130+
stopTaskCmd.Flags().BoolVarP(&stopTaskCmdOpts.ForceSuccess, "force-success", "f", false, "force the task to exit with status code 0")
129131
}

components/supervisor-api/go/terminal.pb.go

Lines changed: 165 additions & 155 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/go/terminal.pb.gw.go

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/java/src/main/java/io/gitpod/supervisor/api/TerminalOuterClass.java

Lines changed: 132 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/terminal.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ message OpenTerminalResponse {
8888

8989
message ShutdownTerminalRequest {
9090
string alias = 1;
91+
bool force_success = 2;
9192
}
9293
message ShutdownTerminalResponse {}
9394

components/supervisor/pkg/supervisor/tasks.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ func (tm *tasksManager) Run(ctx context.Context, wg *sync.WaitGroup, successChan
330330
taskLog.Info("task terminal has been closed. Waiting for watch() to finish...")
331331
taskWatchWg.Wait()
332332
taskLog.Info("watch() has finished, setting task state to closed")
333-
if state != nil {
333+
334+
if term.ForceSuccess {
335+
// Simulate state.Success()
336+
t.successChan <- taskSuccessful
337+
} else if state != nil {
334338
if state.Success() {
335339
t.successChan <- taskSuccessful
336340
} else {

components/supervisor/pkg/terminal/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (srv *MuxTerminalService) OpenWithOptions(ctx context.Context, req *api.Ope
133133

134134
// Close closes a terminal for the given alias.
135135
func (srv *MuxTerminalService) Shutdown(ctx context.Context, req *api.ShutdownTerminalRequest) (*api.ShutdownTerminalResponse, error) {
136-
err := srv.Mux.CloseTerminal(ctx, req.Alias)
136+
err := srv.Mux.CloseTerminal(ctx, req.Alias, req.ForceSuccess)
137137
if err == ErrNotFound {
138138
return nil, status.Error(codes.NotFound, err.Error())
139139
}

0 commit comments

Comments
 (0)