diff --git a/components/gitpod-cli/cmd/timeout-set.go b/components/gitpod-cli/cmd/timeout-set.go index 8ec95d1462312e..29cb566a1d0a15 100644 --- a/components/gitpod-cli/cmd/timeout-set.go +++ b/components/gitpod-cli/cmd/timeout-set.go @@ -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 }, } diff --git a/components/gitpod-cli/cmd/timeout-show.go b/components/gitpod-cli/cmd/timeout-show.go index cefcf84c9ca664..5c7732ab25beac 100644 --- a/components/gitpod-cli/cmd/timeout-show.go +++ b/components/gitpod-cli/cmd/timeout-show.go @@ -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 }, } diff --git a/components/gitpod-protocol/go/gitpod-service.go b/components/gitpod-protocol/go/gitpod-service.go index 6763ca5326432e..441f07197b0163 100644 --- a/components/gitpod-protocol/go/gitpod-service.go +++ b/components/gitpod-protocol/go/gitpod-service.go @@ -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 diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index d9ac3e857aa437..714a5aceeb81b7 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -417,6 +417,7 @@ export interface SetWorkspaceTimeoutResult { export interface GetWorkspaceTimeoutResult { duration: WorkspaceTimeoutDuration; canChange: boolean; + humanReadableDuration: string; } export interface StartWorkspaceResult { diff --git a/components/server/ee/src/workspace/gitpod-server-impl.ts b/components/server/ee/src/workspace/gitpod-server-impl.ts index 161dcf63e6d837..a9da9d0b643a3d 100644 --- a/components/server/ee/src/workspace/gitpod-server-impl.ts +++ b/components/server/ee/src/workspace/gitpod-server-impl.ts @@ -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"); @@ -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 {