Skip to content

Commit

Permalink
gp timeout set and gp timeout show to echo back the server-interp…
Browse files Browse the repository at this point in the history
…reted display duration

This means that 1439m doesn't become "1439 minutes", but rather "29 hours and 59 minutes"
  • Loading branch information
filiptronicek authored and roboquat committed Feb 10, 2023
1 parent 90a865f commit 880f186
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 4 additions & 2 deletions components/gitpod-cli/cmd/timeout-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ For example: 30m or 1h`,
if err != nil {
return GpError{Err: err, OutCome: utils.Outcome_UserErr, ErrorCode: utils.UserErrorCode_InvalidArguments}
}
if _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, duration); err != nil {

res, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, duration)
if err != nil {
if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {
return GpError{OutCome: utils.Outcome_UserErr, Message: "Cannot extend workspace timeout for current plan, please upgrade your plan", ErrorCode: utils.UserErrorCode_NeedUpgradePlan}
}
return err
}
fmt.Printf("Workspace timeout has been set to %d minutes.\n", int(duration.Minutes()))
fmt.Printf("Workspace timeout has been set to %s.\n", res.HumanReadableDuration)
return nil
},
}
Expand Down
6 changes: 1 addition & 5 deletions components/gitpod-cli/cmd/timeout-show.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ var showTimeoutCommand = &cobra.Command{
return err
}

duration, err := time.ParseDuration(res.Duration)
if err != nil {
return err
}
fmt.Printf("Workspace timeout is set to %d minutes.\n", int(duration.Minutes()))
fmt.Printf("Workspace timeout is set to %s.\n", res.HumanReadableDuration)
return nil
},
}
Expand Down
5 changes: 3 additions & 2 deletions components/gitpod-protocol/go/gitpod-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,9 @@ type StartWorkspaceOptions struct {

// GetWorkspaceTimeoutResult is the GetWorkspaceTimeoutResult message type
type GetWorkspaceTimeoutResult struct {
CanChange bool `json:"canChange,omitempty"`
Duration string `json:"duration,omitempty"`
CanChange bool `json:"canChange,omitempty"`
Duration string `json:"duration,omitempty"`
HumanReadableDuration string `json:"humanReadableDuration,omitempty"`
}

// WorkspaceInstancePort is the WorkspaceInstancePort message type
Expand Down
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export interface SetWorkspaceTimeoutResult {
export interface GetWorkspaceTimeoutResult {
duration: WorkspaceTimeoutDuration;
canChange: boolean;
humanReadableDuration: string;
}

export interface StartWorkspaceResult {
Expand Down
4 changes: 2 additions & 2 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
if (!runningInstance) {
log.warn({ userId: user.id, workspaceId }, "Can only get keep-alive for running workspaces");
const duration = WORKSPACE_TIMEOUT_DEFAULT_SHORT;
return { duration, canChange };
return { duration, canChange, humanReadableDuration: this.goDurationToHumanReadable(duration) };
}
await this.guardAccess({ kind: "workspaceInstance", subject: runningInstance, workspace: workspace }, "get");

Expand All @@ -470,7 +470,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
const desc = await client.describeWorkspace(ctx, req);
const duration = desc.getStatus()!.getSpec()!.getTimeout();

return { duration, canChange };
return { duration, canChange, humanReadableDuration: this.goDurationToHumanReadable(duration) };
}

public async isPrebuildDone(ctx: TraceContext, pwsId: string): Promise<boolean> {
Expand Down

0 comments on commit 880f186

Please sign in to comment.