Skip to content

Commit

Permalink
local cli: better logging for ws stop
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Nov 7, 2023
1 parent 8feb819 commit 2662c48
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions components/local-app/cmd/workspace-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,60 @@ var workspaceStopCommand = &cobra.Command{
return err
}

slog.Info("stopping workspace...")
slog.Debug("stopping workspace...")
wsInfo, err := gitpod.Workspaces.StopWorkspace(ctx, connect.NewRequest(&v1.StopWorkspaceRequest{WorkspaceId: workspaceID}))
if err != nil {
return err
}

currentPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase

if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPED {
wsPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase
switch wsPhase {
case v1.WorkspaceInstanceStatus_PHASE_STOPPED:
slog.Info("workspace is already stopped")
return nil
}
if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPING {
case v1.WorkspaceInstanceStatus_PHASE_STOPPING:
slog.Info("workspace is already stopping")
return nil
}

if stopDontWait {
slog.Info("workspace stopping")
return nil
}

stream, err := gitpod.Workspaces.StreamWorkspaceStatus(ctx, connect.NewRequest(&v1.StreamWorkspaceStatusRequest{WorkspaceId: workspaceID}))

if err != nil {
return err
}

slog.Info("waiting for workspace to stop...")
slog.Info("workspace " + prettyprint.FormatWorkspacePhase(currentPhase))

previousStatus := ""

for stream.Receive() {
msg := stream.Msg()
if msg == nil {
slog.Debug("no message received")
continue
}

if msg.GetResult().Instance.Status.Phase == v1.WorkspaceInstanceStatus_PHASE_STOPPED {
slog.Info("workspace stopped")
wsPhase = msg.GetResult().Instance.Status.Phase
switch wsPhase {
case v1.WorkspaceInstanceStatus_PHASE_STOPPED:
{
slog.Info("workspace stopped")
return nil
}
case v1.WorkspaceInstanceStatus_PHASE_RUNNING:
// Skip reporting the "running" status as it is often the initial state and seems confusing to the user.
// There is some delay between requesting a workspace to stop and it actually stopping, so we don't want
// to report "running" in the meantime.
break
}

currentStatus := prettyprint.FormatWorkspacePhase(msg.GetResult().Instance.Status.Phase)
if currentStatus != previousStatus {
slog.Info("workspace " + currentStatus)
previousStatus = currentStatus
default:
{
currentStatus := prettyprint.FormatWorkspacePhase(wsPhase)
if currentStatus != previousStatus {
slog.Info("workspace status: " + currentStatus)
previousStatus = currentStatus
}
}
}
}

Expand Down

0 comments on commit 2662c48

Please sign in to comment.