Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/store/member-idletime.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import {6LicenseIdleTimeouts,7requiresMemberhosting,8} from "@cocalc/util/consts/site-license";9import { Divider, Form, Radio, Typography } from "antd";10import A from "components/misc/A";11const { Text } = Typography;1213interface Props {14form: any;15showExplanations: boolean;16disabled?: boolean;17onChange: () => void;18boost?: boolean;19setPresetAdjusted?: (adjusted: boolean) => void;20}2122export function IdleTimeout(props: Props) {23const {24form,25showExplanations,26onChange,27setPresetAdjusted,28boost = false,29disabled = false,30} = props;3132function idleTimeoutExplanation(): JSX.Element | undefined {33if (!showExplanations) return;3435if (boost) {36return (37<>38The Idle timeout of this Boost license must match the corresponding39Site License you want to boost.40</>41);42}4344const uptime = form.getFieldValue("uptime");45const bottom = (46<>47<br />48<Text italic type="secondary">49Please be aware: licenses with different idle timeouts cannot be50combined!51</Text>52</>53);54const main = (function () {55if (uptime === "always_running") {56return (57<>58<Text strong type="secondary">59Keep projects running:60</Text>{" "}61Once started your project stays running, so you can run very long62computations and also never have to wait for your project to start.63This effectively disables{" "}64<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">65idle timeout66</A>67, since your project will restart automatically if it stops. See{" "}68<A href="https://doc.cocalc.com/project-init.html">69project init scripts70</A>71. (Note: this is NOT guaranteed 100% uptime, since projects may72sometimes restart for security and maintenance reasons.)73</>74);75} else {76return (77<>78Projects stop automatically if they are not actively used.79Increasing{" "}80<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">81idle timeout82</A>{" "}83will allow you to run longer calculations without you having to be84active while they run. However, this is not 100% guaranteed, because85projects may still restart due to maintenance or security reasons.86</>87);88}89})();90return (91<>92{main}93{bottom}94</>95);96}9798function uptimeOptions(): JSX.Element[] {99const ret: JSX.Element[] = [];100for (const [key, it] of Object.entries(LicenseIdleTimeouts)) {101const disabled =102requiresMemberhosting(key) && !form.getFieldValue("member");103ret.push(104<Radio.Button key={key} value={key} disabled={disabled}>105{it.label}106</Radio.Button>,107);108}109ret.push(110<Radio.Button111key={"always_running"}112value={"always_running"}113disabled={!form.getFieldValue("member")}114>115Always running116</Radio.Button>,117);118return ret;119}120121function setUptime(uptime: string) {122form.setFieldsValue({ uptime });123setPresetAdjusted?.(true);124onChange();125}126127return (128<>129<Divider plain>Idle timeout</Divider>130<Form.Item131initialValue="short"132name="uptime"133label="Idle timeout"134extra={idleTimeoutExplanation()}135>136<Radio.Group137disabled={disabled}138onChange={(e) => setUptime(e.target.value)}139>140{uptimeOptions()}141</Radio.Group>142</Form.Item>143</>144);145}146147148