Skip to content

Commit dd7f8d0

Browse files
committed
gp timeout set and gp timeout show to echo back the server-interpreted display duration
This means that 1439m doesn't become "1439 minutes", but rather "29 hours and 59 minutes"
1 parent 3faf828 commit dd7f8d0

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

components/gitpod-cli/cmd/timeout-set.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ For example: 30m or 1h`,
4545
if err != nil {
4646
return GpError{Err: err, OutCome: utils.Outcome_UserErr, ErrorCode: utils.UserErrorCode_InvalidArguments}
4747
}
48-
if _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, duration); err != nil {
48+
49+
res, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, duration)
50+
if err != nil {
4951
if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {
5052
return GpError{OutCome: utils.Outcome_UserErr, Message: "Cannot extend workspace timeout for current plan, please upgrade your plan", ErrorCode: utils.UserErrorCode_NeedUpgradePlan}
5153
}
5254
return err
5355
}
54-
fmt.Printf("Workspace timeout has been set to %d minutes.\n", int(duration.Minutes()))
56+
fmt.Printf("Workspace timeout has been set to %s.\n", res.HumanReadableDuration)
5557
return nil
5658
},
5759
}

components/gitpod-cli/cmd/timeout-show.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ var showTimeoutCommand = &cobra.Command{
3838
return err
3939
}
4040

41-
duration, err := time.ParseDuration(res.Duration)
42-
if err != nil {
43-
return err
44-
}
45-
fmt.Printf("Workspace timeout is set to %d minutes.\n", int(duration.Minutes()))
41+
fmt.Printf("Workspace timeout is set to %s\n", res.HumanReadableDuration)
4642
return nil
4743
},
4844
}

components/gitpod-protocol/go/gitpod-service.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1898,8 +1898,9 @@ type StartWorkspaceOptions struct {
18981898

18991899
// GetWorkspaceTimeoutResult is the GetWorkspaceTimeoutResult message type
19001900
type GetWorkspaceTimeoutResult struct {
1901-
CanChange bool `json:"canChange,omitempty"`
1902-
Duration string `json:"duration,omitempty"`
1901+
CanChange bool `json:"canChange,omitempty"`
1902+
Duration string `json:"duration,omitempty"`
1903+
HumanReadableDuration string `json:"humanReadableDuration,omitempty"`
19031904
}
19041905

19051906
// WorkspaceInstancePort is the WorkspaceInstancePort message type

components/gitpod-protocol/src/gitpod-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ export interface SetWorkspaceTimeoutResult {
417417
export interface GetWorkspaceTimeoutResult {
418418
duration: WorkspaceTimeoutDuration;
419419
canChange: boolean;
420+
humanReadableDuration: string;
420421
}
421422

422423
export interface StartWorkspaceResult {

components/server/ee/src/workspace/gitpod-server-impl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
456456
if (!runningInstance) {
457457
log.warn({ userId: user.id, workspaceId }, "Can only get keep-alive for running workspaces");
458458
const duration = WORKSPACE_TIMEOUT_DEFAULT_SHORT;
459-
return { duration, canChange };
459+
return { duration, canChange, humanReadableDuration: this.goDurationToHumanReadable(duration) };
460460
}
461461
await this.guardAccess({ kind: "workspaceInstance", subject: runningInstance, workspace: workspace }, "get");
462462

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

473-
return { duration, canChange };
473+
return { duration, canChange, humanReadableDuration: this.goDurationToHumanReadable(duration) };
474474
}
475475

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

0 commit comments

Comments
 (0)