Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/compute-states.ts
5836 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { defineMessage } from "react-intl";
7
8
import { IntlMessage } from "./i18n/types";
9
10
// Compute related schema stuff (see compute.coffee)
11
//
12
// Here's a picture of the finite state machine defined below:
13
//
14
// ----------[closing] ------- --------- [stopping] <--------
15
// \|/ \|/ |
16
// [archived] <--> [closed] --> [opening] --> [opened] --> [starting] --> [running]
17
//
18
// [unarchiving] [pending]
19
// [archiving]
20
//
21
//
22
// The icon names below refer to font-awesome, and are used in the UI.
23
24
export type State =
25
| "archived"
26
| "archiving"
27
| "closed"
28
| "closing"
29
| "opened"
30
| "opening"
31
| "pending"
32
| "running"
33
| "starting"
34
| "stopping"
35
| "unarchiving";
36
37
// @hsy: completely unclear what this is for.
38
type Operation =
39
| "open"
40
| "archived"
41
| "unarchive"
42
| "start"
43
| "stop"
44
| "close"
45
| "closed";
46
47
// These icon names must be a subset of the known names in frontend/componten/icon.tsx (we can't import IconName here, though)
48
export type ComputeStateIcon =
49
| "file-archive"
50
| "download"
51
| "paper-plane"
52
| "gears"
53
| "stop"
54
| "times-rectangle"
55
| "flash"
56
| "hand-stop"
57
| "run";
58
59
export type ComputeState = {
60
desc: IntlMessage; // shows up in the UI (default)
61
desc_cocalccom?: IntlMessage; // if set, use this string instead of desc in "cocalc.com" mode
62
icon: ComputeStateIcon;
63
display: IntlMessage;
64
stable?: boolean;
65
to: { [key in Operation]?: State };
66
timeout?: number;
67
commands: Readonly<string[]>;
68
};
69
70
type ComputeStates = Readonly<{
71
[key in State]: ComputeState;
72
}>;
73
74
// ATTN: in the frontend, all "display" and "desc" strings are translated in the components/project-state file.
75
76
export const COMPUTE_STATES: ComputeStates = {
77
archived: {
78
desc: defineMessage({
79
id: "util.compute-states.archived.desc",
80
defaultMessage:
81
"Project is stored in longterm storage, and will take even longer to start.",
82
}),
83
icon: "file-archive",
84
display: defineMessage({
85
id: "util.compute-states.archived.display",
86
defaultMessage: "Archived", // displayed name for users
87
}),
88
stable: true,
89
to: {
90
closed: "unarchiving",
91
},
92
commands: ["unarchive"],
93
},
94
95
unarchiving: {
96
desc: defineMessage({
97
id: "util.compute-states.unarchiving.desc",
98
defaultMessage:
99
"Project is being copied from longterm storage; this may take several minutes depending on how many files you have.",
100
}),
101
icon: "download",
102
display: defineMessage({
103
id: "util.compute-states.unarchiving.display",
104
defaultMessage: "Restoring",
105
}),
106
to: {},
107
timeout: 30 * 60,
108
commands: ["status", "mintime"],
109
},
110
111
archiving: {
112
desc: defineMessage({
113
id: "util.compute-states.archiving.desc",
114
defaultMessage: "Project is being archived to longterm storage.",
115
}),
116
icon: "paper-plane",
117
display: defineMessage({
118
id: "util.compute-states.archiving.display",
119
defaultMessage: "Archiving",
120
}),
121
to: {},
122
timeout: 5 * 60,
123
commands: ["status", "mintime"],
124
},
125
126
closed: {
127
desc: defineMessage({
128
id: "util.compute-states.closed.desc",
129
defaultMessage:
130
"Project is archived and needs to be decompressed, so it will take longer to start.",
131
}),
132
icon: "file-archive", // font awesome icon
133
display: defineMessage({
134
id: "util.compute-states.closed.display",
135
defaultMessage: "Closed", // displayed name for users
136
}),
137
stable: true,
138
to: {
139
open: "opening",
140
archived: "archiving",
141
},
142
commands: ["open", "move", "status", "destroy", "mintime", "archive"],
143
},
144
145
opening: {
146
desc: defineMessage({
147
id: "util.compute-states.opening.desc",
148
defaultMessage:
149
"Project is being imported; this may take several minutes depending on size.",
150
}),
151
icon: "gears",
152
display: defineMessage({
153
id: "util.compute-states.opening.display",
154
defaultMessage: "Opening",
155
}),
156
to: {},
157
timeout: 30 * 60,
158
commands: ["status", "mintime"],
159
},
160
161
closing: {
162
desc: defineMessage({
163
id: "util.compute-states.closing.desc",
164
defaultMessage: "Project is in the process of being closed.",
165
}),
166
icon: "download",
167
display: defineMessage({
168
id: "util.compute-states.closing.display",
169
defaultMessage: "Closing",
170
}),
171
to: {},
172
timeout: 5 * 60,
173
commands: ["status", "mintime"],
174
},
175
176
opened: {
177
desc: defineMessage({
178
id: "util.compute-states.opened.desc",
179
defaultMessage: "Project is available and ready to run.",
180
}),
181
icon: "stop",
182
display: defineMessage({
183
id: "util.compute-states.opened.display",
184
defaultMessage: "Stopped",
185
}),
186
stable: true,
187
to: {
188
start: "starting",
189
close: "closing",
190
},
191
commands: [
192
"start",
193
"close",
194
"save",
195
"copy_path",
196
"mkdir",
197
"directory_listing",
198
"read_file",
199
"network",
200
"mintime",
201
"disk_quota",
202
"compute_quota",
203
"status",
204
"migrate_live",
205
"ephemeral_state",
206
"ephemeral_disk",
207
],
208
},
209
210
pending: {
211
desc_cocalccom: defineMessage({
212
id: "util.compute-states.pending.desc_cocalccom",
213
defaultMessage:
214
"Finding a place to run your project. If nothing becomes available, reduce RAM or CPU, pay for members only hosting, or contact support.",
215
}),
216
desc: defineMessage({
217
id: "util.compute-states.pending.desc",
218
defaultMessage:
219
"Finding a place to run your project. If nothing becomes available, contact your administrator.",
220
}),
221
icon: "times-rectangle",
222
display: defineMessage({
223
id: "util.compute-states.pending.display",
224
defaultMessage: "Pending",
225
}),
226
stable: true,
227
to: {
228
stop: "stopping",
229
},
230
commands: ["stop"],
231
},
232
233
starting: {
234
desc: defineMessage({
235
id: "util.compute-states.starting.desc",
236
defaultMessage: "Project is starting up.",
237
}),
238
icon: "flash",
239
display: defineMessage({
240
id: "util.compute-states.starting.display",
241
defaultMessage: "Starting",
242
}),
243
to: {},
244
timeout: 60,
245
commands: [
246
"save",
247
"copy_path",
248
"mkdir",
249
"directory_listing",
250
"read_file",
251
"network",
252
"mintime",
253
"disk_quota",
254
"compute_quota",
255
"status",
256
],
257
},
258
259
stopping: {
260
desc: defineMessage({
261
id: "util.compute-states.stopping.desc",
262
defaultMessage: "Project is stopping.",
263
}),
264
icon: "hand-stop",
265
display: defineMessage({
266
id: "util.compute-states.stopping.display",
267
defaultMessage: "Stopping",
268
}),
269
timeout: 60,
270
to: {},
271
commands: [
272
"save",
273
"copy_path",
274
"mkdir",
275
"directory_listing",
276
"read_file",
277
"network",
278
"mintime",
279
"disk_quota",
280
"compute_quota",
281
"status",
282
],
283
},
284
285
running: {
286
desc: defineMessage({
287
id: "util.compute-states.running.desc",
288
defaultMessage: "Project is running.",
289
}),
290
icon: "run",
291
display: defineMessage({
292
id: "util.compute-states.running.display",
293
defaultMessage: "Running",
294
}),
295
stable: true,
296
to: {
297
stop: "stopping",
298
},
299
commands: [
300
"stop",
301
"save",
302
"address",
303
"copy_path",
304
"mkdir",
305
"directory_listing",
306
"read_file",
307
"network",
308
"mintime",
309
"disk_quota",
310
"compute_quota",
311
"status",
312
"migrate_live",
313
],
314
},
315
} as const;
316
317