Path: blob/master/src/packages/next/components/store/member-idletime.tsx
1450 views
/*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";11import type { JSX } from "react";12const { Text } = Typography;1314interface Props {15form: any;16showExplanations: boolean;17disabled?: boolean;18onChange: () => void;19boost?: boolean;20setPresetAdjusted?: (adjusted: boolean) => void;21}2223export function IdleTimeout(props: Props) {24const {25form,26showExplanations,27onChange,28setPresetAdjusted,29boost = false,30disabled = false,31} = props;3233function idleTimeoutExplanation(): JSX.Element | undefined {34if (!showExplanations) return;3536if (boost) {37return (38<>39The Idle timeout of this Boost license must match the corresponding40Site License you want to boost.41</>42);43}4445const uptime = form.getFieldValue("uptime");46const bottom = (47<>48<br />49<Text italic type="secondary">50Please be aware: licenses with different idle timeouts cannot be51combined!52</Text>53</>54);55const main = (function () {56if (uptime === "always_running") {57return (58<>59<Text strong type="secondary">60Keep projects running:61</Text>{" "}62Once started your project stays running, so you can run very long63computations and also never have to wait for your project to start.64This effectively disables{" "}65<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">66idle timeout67</A>68, since your project will restart automatically if it stops. See{" "}69<A href="https://doc.cocalc.com/project-init.html">70project init scripts71</A>72. (Note: this is NOT guaranteed 100% uptime, since projects may73sometimes restart for security and maintenance reasons.)74</>75);76} else {77return (78<>79Projects stop automatically if they are not actively used.80Increasing{" "}81<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">82idle timeout83</A>{" "}84will allow you to run longer calculations without you having to be85active while they run. However, this is not 100% guaranteed, because86projects may still restart due to maintenance or security reasons.87</>88);89}90})();91return (92<>93{main}94{bottom}95</>96);97}9899function uptimeOptions(): JSX.Element[] {100const ret: JSX.Element[] = [];101for (const [key, it] of Object.entries(LicenseIdleTimeouts)) {102const disabled =103requiresMemberhosting(key) && !form.getFieldValue("member");104ret.push(105<Radio.Button key={key} value={key} disabled={disabled}>106{it.label}107</Radio.Button>,108);109}110ret.push(111<Radio.Button112key={"always_running"}113value={"always_running"}114disabled={!form.getFieldValue("member")}115>116Always running117</Radio.Button>,118);119return ret;120}121122function setUptime(uptime: string) {123form.setFieldsValue({ uptime });124setPresetAdjusted?.(true);125onChange();126}127128return (129<>130<Divider plain>Idle timeout</Divider>131<Form.Item132initialValue="short"133name="uptime"134label="Idle timeout"135extra={idleTimeoutExplanation()}136>137<Radio.Group138disabled={disabled}139onChange={(e) => setUptime(e.target.value)}140>141{uptimeOptions()}142</Radio.Group>143</Form.Item>144</>145);146}147148149