Skip to content

Commit

Permalink
Add humanReadableDuration as return value from setWorkspaceTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Feb 7, 2023
1 parent 869ffcf commit 8af4a7e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/gitpod-protocol/go/gitpod-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,7 @@ type GetTokenSearchOptions struct {
// SetWorkspaceTimeoutResult is the SetWorkspaceTimeoutResult message type
type SetWorkspaceTimeoutResult struct {
ResetTimeoutOnWorkspaces []string `json:"resetTimeoutOnWorkspaces,omitempty"`
HumanReadableDuration string `json:"humanReadableDuration,omitempty"`
}

// UserMessage is the UserMessage message type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

public class SetWorkspaceTimeoutResult {
private String[] resetTimeoutOnWorkspaces;
private String humanReadableDuration;

public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces) {
public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces, String humanReadableDuration) {
this.resetTimeoutOnWorkspaces = resetTimeoutOnWorkspaces;
this.humanReadableDuration = humanReadableDuration;
}

public String[] getResetTimeoutOnWorkspaces() {
return resetTimeoutOnWorkspaces;
}

public String getHumanReadableDuration() {
return humanReadableDuration;
}
}
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 @@ -402,6 +402,7 @@ export const createServerMock = function <C extends GitpodClient, S extends Gitp

export interface SetWorkspaceTimeoutResult {
resetTimeoutOnWorkspaces: string[];
humanReadableDuration: string;
}

export interface GetWorkspaceTimeoutResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ExtendWorkspaceTimeoutAction : AnAction() {
val dialog = InputDurationDialog()
if (dialog.showAndGet()) {
val duration = dialog.getDuration()
manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { _, e ->
manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { result, e ->
var message: String
var notificationType: NotificationType

Expand All @@ -85,7 +85,7 @@ class ExtendWorkspaceTimeoutAction : AnAction() {
notificationType = NotificationType.ERROR
thisLogger().error("gitpod: failed to extend workspace timeout", e)
} else {
message = "Workspace timeout has been extended to ${duration}."
message = "Workspace timeout has been extended to ${result.humanReadableDuration}."
notificationType = NotificationType.INFORMATION
}

Expand Down
33 changes: 33 additions & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,38 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
return { valid: true };
}

goDurationToHumanReadable(goDuration: string): string {
const [, value, unit] = goDuration.match(/^(\d+)([mh])$/)!;
let duration = parseInt(value);

switch (unit) {
case "m":
duration *= 60;
break;
case "h":
duration *= 60 * 60;
break;
}

const hours = Math.floor(duration / 3600);
duration %= 3600;
const minutes = Math.floor(duration / 60);
duration %= 60;

let result = "";
if (hours) {
result += `${hours} hour${hours === 1 ? "" : "s"}`;
if (minutes) {
result += " and ";
}
}
if (minutes) {
result += `${minutes} minute${minutes === 1 ? "" : "s"}`;
}

return result;
}

public async setWorkspaceTimeout(
ctx: TraceContext,
workspaceId: string,
Expand Down Expand Up @@ -404,6 +436,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {

return {
resetTimeoutOnWorkspaces: [workspace.id],
humanReadableDuration: this.goDurationToHumanReadable(validatedDuration),
};
}

Expand Down

0 comments on commit 8af4a7e

Please sign in to comment.