CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/store/member-idletime.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import {
7
LicenseIdleTimeouts,
8
requiresMemberhosting,
9
} from "@cocalc/util/consts/site-license";
10
import { Divider, Form, Radio, Typography } from "antd";
11
import A from "components/misc/A";
12
const { Text } = Typography;
13
14
interface Props {
15
form: any;
16
showExplanations: boolean;
17
disabled?: boolean;
18
onChange: () => void;
19
boost?: boolean;
20
setPresetAdjusted?: (adjusted: boolean) => void;
21
}
22
23
export function IdleTimeout(props: Props) {
24
const {
25
form,
26
showExplanations,
27
onChange,
28
setPresetAdjusted,
29
boost = false,
30
disabled = false,
31
} = props;
32
33
function idleTimeoutExplanation(): JSX.Element | undefined {
34
if (!showExplanations) return;
35
36
if (boost) {
37
return (
38
<>
39
The Idle timeout of this Boost license must match the corresponding
40
Site License you want to boost.
41
</>
42
);
43
}
44
45
const uptime = form.getFieldValue("uptime");
46
const bottom = (
47
<>
48
<br />
49
<Text italic type="secondary">
50
Please be aware: licenses with different idle timeouts cannot be
51
combined!
52
</Text>
53
</>
54
);
55
const main = (function () {
56
if (uptime === "always_running") {
57
return (
58
<>
59
<Text strong type="secondary">
60
Keep projects running:
61
</Text>{" "}
62
Once started your project stays running, so you can run very long
63
computations and also never have to wait for your project to start.
64
This effectively disables{" "}
65
<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">
66
idle timeout
67
</A>
68
, since your project will restart automatically if it stops. See{" "}
69
<A href="https://doc.cocalc.com/project-init.html">
70
project init scripts
71
</A>
72
. (Note: this is NOT guaranteed 100% uptime, since projects may
73
sometimes restart for security and maintenance reasons.)
74
</>
75
);
76
} else {
77
return (
78
<>
79
Projects stop automatically if they are not actively used.
80
Increasing{" "}
81
<A href="https://doc.cocalc.com/howto/software-development.html#idle-timeout">
82
idle timeout
83
</A>{" "}
84
will allow you to run longer calculations without you having to be
85
active while they run. However, this is not 100% guaranteed, because
86
projects may still restart due to maintenance or security reasons.
87
</>
88
);
89
}
90
})();
91
return (
92
<>
93
{main}
94
{bottom}
95
</>
96
);
97
}
98
99
function uptimeOptions(): JSX.Element[] {
100
const ret: JSX.Element[] = [];
101
for (const [key, it] of Object.entries(LicenseIdleTimeouts)) {
102
const disabled =
103
requiresMemberhosting(key) && !form.getFieldValue("member");
104
ret.push(
105
<Radio.Button key={key} value={key} disabled={disabled}>
106
{it.label}
107
</Radio.Button>,
108
);
109
}
110
ret.push(
111
<Radio.Button
112
key={"always_running"}
113
value={"always_running"}
114
disabled={!form.getFieldValue("member")}
115
>
116
Always running
117
</Radio.Button>,
118
);
119
return ret;
120
}
121
122
function setUptime(uptime: string) {
123
form.setFieldsValue({ uptime });
124
setPresetAdjusted?.(true);
125
onChange();
126
}
127
128
return (
129
<>
130
<Divider plain>Idle timeout</Divider>
131
<Form.Item
132
initialValue="short"
133
name="uptime"
134
label="Idle timeout"
135
extra={idleTimeoutExplanation()}
136
>
137
<Radio.Group
138
disabled={disabled}
139
onChange={(e) => setUptime(e.target.value)}
140
>
141
{uptimeOptions()}
142
</Radio.Group>
143
</Form.Item>
144
</>
145
);
146
}
147
148