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/frontend/compute/check-in.ts
Views: 687
1
import { CHECK_IN_PATH } from "@cocalc/util/db-schema/compute-servers";
2
import { webapp_client } from "@cocalc/frontend/webapp-client";
3
import { redux } from "@cocalc/frontend/app-framework";
4
5
// cause the given compute server to check in, or all running compute
6
// servers in the project if compute_server_id isn't specified.
7
export async function checkIn({
8
project_id,
9
compute_server_id,
10
}: {
11
project_id: string;
12
compute_server_id: number;
13
}) {
14
if (compute_server_id != null) {
15
await webapp_client.project_client.exec({
16
command: "touch",
17
args: [CHECK_IN_PATH],
18
project_id,
19
compute_server_id,
20
});
21
return;
22
}
23
}
24
25
// launches in parallel check in on all running projects; doesn't
26
// wait for response.
27
export function checkInAll(project_id) {
28
const computeServers = redux
29
.getProjectStore(project_id)
30
.get("compute_servers");
31
if (computeServers == null) {
32
return;
33
}
34
const ids = computeServers
35
.filter((x) => x.get("state") == "running")
36
.map((x) => x.get("id"))
37
.keySeq();
38
for (const id of ids) {
39
(async () => {
40
try {
41
await checkIn({ project_id, compute_server_id: id });
42
} catch (err) {
43
console.warn(`checkIn issue with compute server ${id}`, err);
44
}
45
})();
46
}
47
}
48
49