Skip to content

allow user customize workspace timeout #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gitpod-remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"title": "%extendTimeout%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.setWorkspaceTimeout",
"title": "%customizeTimeout%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.takeSnapshot",
"title": "%takeSnapshot%",
Expand Down
3 changes: 2 additions & 1 deletion gitpod-remote/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"reportIssue": "Gitpod: Report Issue",
"stopWorkspace": "Gitpod: Stop Workspace",
"upgradeSubscription": "Gitpod: Upgrade Subscription",
"extendTimeout": "Gitpod: Extend Workspace Timeout",
"extendTimeout": "Gitpod: Extend Workspace Timeout (180m)",
"configureTimeout": "Gitpod: Configure Workspace Timeout",
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
"shareWorkspace": "Gitpod: Share Running Workspace",
"stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace",
Expand Down
2 changes: 1 addition & 1 deletion gitpod-shared/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type GitpodAnalyticsEvent =
targetQualifier?: 'stable' | 'insiders';
}> |
GAET<'vscode_execute_command_gitpod_workspace', {
action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout';
action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout'| 'configure-timeout';
}> |
GAET<'vscode_execute_command_gitpod_ports', {
action: 'private' | 'public' | 'preview' | 'openBrowser' | 'urlCopy';
Expand Down
41 changes: 31 additions & 10 deletions gitpod-shared/src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export async function registerWorkspaceCommands(context: GitpodExtensionContext)
return context.gitpod.server.stopWorkspace(context.info.workspaceId);
}));
context.subscriptions.push(vscode.commands.registerCommand('gitpod.upgradeSubscription', () => {
const url = new GitpodHostUrl(context.info.gitpodHost).asUpgradeSubscription().toString();
const url = new GitpodHostUrl(context.info.gitpodHost).asBilling().toString();
context.fireAnalyticsEvent({
eventName: 'vscode_execute_command_gitpod_open_link',
properties: { url }
Expand Down Expand Up @@ -387,36 +387,57 @@ export async function registerWorkspaceTimeout(context: GitpodExtensionContext):
}
});
try {
const result = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m');
if (result.resetTimeoutOnWorkspaces?.length > 0) {
vscode.window.showWarningMessage('Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces.');
} else {
vscode.window.showInformationMessage('Workspace timeout has been extended to three hours.');
}
await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, '180m');
vscode.window.showWarningMessage(`Workspace timeout has been extended to 180m.`);
} catch (err) {
vscode.window.showErrorMessage(`Cannot extend workspace timeout: ${err.toString()}`);
}
}));


context.subscriptions.push(vscode.commands.registerCommand('gitpod.setWorkspaceTimeout', async () => {
const timeout = await vscode.window.showInputBox({
value: '180m',
prompt: 'Please input the timeout time, such as 30m, 1h, 2h, 3h',
});
if (!timeout) {
return;
}
context.fireAnalyticsEvent({
eventName: 'vscode_execute_command_gitpod_workspace',
properties: {
action: 'configure-timeout'
}
});
try {
const { humanReadableDuration } = await context.gitpod.server.setWorkspaceTimeout(context.info.workspaceId, timeout);
vscode.window.showWarningMessage(`Workspace timeout has been changed to ${humanReadableDuration ?? timeout}.`);
} catch (err) {
vscode.window.showErrorMessage(`Cannot configure workspace timeout: ${err.toString()}`);
}
}));

const workspaceTimeout = await context.gitpod.server.getWorkspaceTimeout(context.info.workspaceId);
if (!workspaceTimeout.canChange) {
return;
}

const listener = await context.instanceListener;
const extendTimeoutStatusBarItem = vscode.window.createStatusBarItem('gitpod.extendTimeout', vscode.StatusBarAlignment.Right, -100);
extendTimeoutStatusBarItem.name = 'Click to extend the workspace timeout.';
extendTimeoutStatusBarItem.name = 'Extend the workspace timeout.';
context.subscriptions.push(extendTimeoutStatusBarItem);
extendTimeoutStatusBarItem.text = '$(watch)';
extendTimeoutStatusBarItem.command = 'gitpod.ExtendTimeout';
extendTimeoutStatusBarItem.command = 'gitpod.setWorkspaceTimeout';
const update = () => {
const instance = listener.info.latestInstance;
if (!instance) {
extendTimeoutStatusBarItem.hide();
return;
}
extendTimeoutStatusBarItem.tooltip = `Workspace Timeout: ${instance.status.timeout}. Click to extend.`;
extendTimeoutStatusBarItem.color = instance.status.timeout === '180m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined;

// TODO: query default timeout, currently all paid plan default timeout is 60m.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this icon was highlighted if the workspace timeout was extended to 180 minutes, but now that this condition has been changed with the ability to customize the timeout, how should we handle this highlighting logic?

And in the feature if the user already customizes workspace timeout time, it will also disable closed timeout, do we need to tell the user?

Copy link
Member

@loujaybee loujaybee Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in the feature if the user already customizes workspace timeout time, it will also disable closed timeout, do we need to tell the user?

Interesting question. We can document this, but I don't think there's much we can do help the user in the product? Could we add it to the copy from the confirmation toast modal? 💭

extendTimeoutStatusBarItem.color = instance.status.timeout !== '60m' ? new vscode.ThemeColor('notificationsWarningIcon.foreground') : undefined;
extendTimeoutStatusBarItem.show();
};
update();
Expand Down
19 changes: 12 additions & 7 deletions gitpod-shared/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


"@gitpod/gitpod-protocol@main":
version "0.1.5-main.6379"
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6379.tgz#8c654e9d1658a62648ec4a1bc837f3d5756f8a14"
integrity sha512-QLScSNODhMle/w23HSr3RihIh7S+ZE46JRbOqbFgR9+a0FBoxPtHi6kqUmeNgqvt+hfyjgdPG5/yddU7j0uznA==
version "0.1.5-main.6559"
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6559.tgz#e771beee25447b12dce79fea4abad4caed8db9fc"
integrity sha512-v6E5AnpiTkWEBhyuBT8/gXVYzSKHUK1IUoa9CCr3q5jsdgG0egGzotcsu1OTmDZ68R1UKCvu4RddQZgU5ZGTjg==
dependencies:
"@types/react" "17.0.32"
abort-controller-x "^0.4.0"
Expand Down Expand Up @@ -589,9 +589,9 @@ [email protected]:
safe-buffer "5.2.1"

content-type@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==
version "1.0.5"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==

[email protected]:
version "1.0.6"
Expand Down Expand Up @@ -1222,7 +1222,12 @@ minimatch@^3.0.4, minimatch@^3.1.1:
dependencies:
brace-expansion "^1.1.7"

minimist@^1.1.0, minimist@^1.2.0, minimist@^1.2.6:
minimist@^1.1.0:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==

minimist@^1.2.0, minimist@^1.2.6:
version "1.2.7"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==
Expand Down
5 changes: 5 additions & 0 deletions gitpod-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
"title": "%extendTimeout%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.setWorkspaceTimeout",
"title": "%configureTimeout%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.takeSnapshot",
"title": "%takeSnapshot%",
Expand Down
3 changes: 2 additions & 1 deletion gitpod-web/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"stopWorkspace": "Gitpod: Stop Workspace",
"showReleaseNotes": "Gitpod: Show Release Notes",
"upgradeSubscription": "Gitpod: Upgrade Subscription",
"extendTimeout": "Gitpod: Extend Workspace Timeout",
"extendTimeout": "Gitpod: Extend Workspace Timeout (180m)",
"configureTimeout": "Gitpod: Configure Workspace Timeout",
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
"shareWorkspace": "Gitpod: Share Running Workspace",
"stopSharingWorkspace": "Gitpod: Stop Sharing Running Workspace",
Expand Down