Skip to content

Commit 2662c48

Browse files
committed
local cli: better logging for ws stop
1 parent 8feb819 commit 2662c48

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

components/local-app/cmd/workspace-stop.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,60 @@ var workspaceStopCommand = &cobra.Command{
3434
return err
3535
}
3636

37-
slog.Info("stopping workspace...")
37+
slog.Debug("stopping workspace...")
3838
wsInfo, err := gitpod.Workspaces.StopWorkspace(ctx, connect.NewRequest(&v1.StopWorkspaceRequest{WorkspaceId: workspaceID}))
3939
if err != nil {
4040
return err
4141
}
4242

43-
currentPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase
44-
45-
if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPED {
43+
wsPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase
44+
switch wsPhase {
45+
case v1.WorkspaceInstanceStatus_PHASE_STOPPED:
4646
slog.Info("workspace is already stopped")
47-
return nil
48-
}
49-
if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPING {
47+
case v1.WorkspaceInstanceStatus_PHASE_STOPPING:
5048
slog.Info("workspace is already stopping")
51-
return nil
5249
}
50+
5351
if stopDontWait {
5452
slog.Info("workspace stopping")
5553
return nil
5654
}
5755

5856
stream, err := gitpod.Workspaces.StreamWorkspaceStatus(ctx, connect.NewRequest(&v1.StreamWorkspaceStatusRequest{WorkspaceId: workspaceID}))
59-
6057
if err != nil {
6158
return err
6259
}
6360

6461
slog.Info("waiting for workspace to stop...")
65-
slog.Info("workspace " + prettyprint.FormatWorkspacePhase(currentPhase))
6662

6763
previousStatus := ""
68-
6964
for stream.Receive() {
7065
msg := stream.Msg()
7166
if msg == nil {
7267
slog.Debug("no message received")
7368
continue
7469
}
7570

76-
if msg.GetResult().Instance.Status.Phase == v1.WorkspaceInstanceStatus_PHASE_STOPPED {
77-
slog.Info("workspace stopped")
71+
wsPhase = msg.GetResult().Instance.Status.Phase
72+
switch wsPhase {
73+
case v1.WorkspaceInstanceStatus_PHASE_STOPPED:
74+
{
75+
slog.Info("workspace stopped")
76+
return nil
77+
}
78+
case v1.WorkspaceInstanceStatus_PHASE_RUNNING:
79+
// Skip reporting the "running" status as it is often the initial state and seems confusing to the user.
80+
// There is some delay between requesting a workspace to stop and it actually stopping, so we don't want
81+
// to report "running" in the meantime.
7882
break
79-
}
80-
81-
currentStatus := prettyprint.FormatWorkspacePhase(msg.GetResult().Instance.Status.Phase)
82-
if currentStatus != previousStatus {
83-
slog.Info("workspace " + currentStatus)
84-
previousStatus = currentStatus
83+
default:
84+
{
85+
currentStatus := prettyprint.FormatWorkspacePhase(wsPhase)
86+
if currentStatus != previousStatus {
87+
slog.Info("workspace status: " + currentStatus)
88+
previousStatus = currentStatus
89+
}
90+
}
8591
}
8692
}
8793

0 commit comments

Comments
 (0)