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