Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/service/syncfs-client.ts
1452 views
1
/*
2
This is a *service* that runs in the filesystem part of a compute server.
3
4
It's called "syncfs-client" because it runs on the client part of the filesystem
5
that compute servers use.
6
*/
7
8
import { createServiceClient, createServiceHandler } from "./typed";
9
10
interface SyncFsApiClient {
11
// cause the compute server to initiate a sync asap.
12
sync: () => Promise<void>;
13
14
// copy files from compute server to the home base
15
copyFilesToHomeBase: (opts: {
16
paths: string[];
17
dest?: string;
18
}) => Promise<void>;
19
20
// copy files from the home base to the compute server
21
copyFilesFromHomeBase: (opts: {
22
paths: string[];
23
dest?: string;
24
}) => Promise<void>;
25
}
26
27
export function syncFsClientClient({
28
compute_server_id,
29
project_id,
30
// default is large, because sync tends to take a
31
// longer time, as does copying files around.
32
timeout = 90000,
33
}: {
34
compute_server_id: number;
35
project_id: string;
36
timeout?: number;
37
}) {
38
return createServiceClient<SyncFsApiClient>({
39
project_id,
40
compute_server_id,
41
service: "syncfs-client",
42
timeout,
43
});
44
}
45
46
export async function createSyncFsClientService({
47
compute_server_id,
48
project_id,
49
impl,
50
}: {
51
project_id: string;
52
compute_server_id: number;
53
impl: SyncFsApiClient;
54
}) {
55
return await createServiceHandler<SyncFsApiClient>({
56
project_id,
57
compute_server_id,
58
service: "syncfs-client",
59
description: "SyncFs client service that runs on each compute server.",
60
impl,
61
});
62
}
63
64