Skip to content

Commit f42a47f

Browse files
committed
add isRunning function to project api; will be useful for showing state for compute servers
1 parent 1ffac00 commit f42a47f

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/packages/conat/project/api/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ProjectApi {
1010
editor: Editor;
1111
jupyter: Jupyter;
1212
sync: Sync;
13+
isRunning: () => Promise<boolean>;
1314
}
1415

1516
const ProjectApiStructure = {
@@ -19,7 +20,7 @@ const ProjectApiStructure = {
1920
sync,
2021
} as const;
2122

22-
export function initProjectApi(callProjectApi): ProjectApi {
23+
export function initProjectApi(callProjectApi, isRunning): ProjectApi {
2324
const projectApi: any = {};
2425
for (const group in ProjectApiStructure) {
2526
if (projectApi[group] == null) {
@@ -35,5 +36,6 @@ export function initProjectApi(callProjectApi): ProjectApi {
3536
);
3637
}
3738
}
39+
projectApi.isRunning = isRunning;
3840
return projectApi as ProjectApi;
3941
}

src/packages/conat/project/api/project-client.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isValidUUID } from "@cocalc/util/misc";
88
import { type ProjectApi, initProjectApi } from "./index";
99

1010
const DEFAULT_TIMEOUT = 15000;
11+
const service = "api";
1112

1213
export function projectApiClient({
1314
project_id,
@@ -23,38 +24,37 @@ export function projectApiClient({
2324
if (!isValidUUID(project_id)) {
2425
throw Error(`project_id = '${project_id}' must be a valid uuid`);
2526
}
27+
const subject = projectSubject({ project_id, compute_server_id, service });
28+
29+
const isRunning = async () => {
30+
return await client.interest(subject);
31+
};
32+
2633
const callProjectApi = async ({ name, args }) => {
2734
return await callProject({
2835
client,
29-
project_id,
30-
compute_server_id,
36+
subject,
3137
timeout,
32-
service: "api",
3338
name,
3439
args,
3540
});
3641
};
37-
return initProjectApi(callProjectApi);
42+
return initProjectApi(callProjectApi, isRunning);
3843
}
3944

4045
async function callProject({
4146
client,
42-
service = "api",
43-
project_id,
44-
compute_server_id,
47+
subject,
4548
name,
4649
args = [],
4750
timeout = DEFAULT_TIMEOUT,
4851
}: {
4952
client: Client;
50-
service?: string;
51-
project_id: string;
52-
compute_server_id?: number;
53+
subject: string;
5354
name: string;
5455
args: any[];
5556
timeout?: number;
5657
}) {
57-
const subject = projectSubject({ project_id, compute_server_id, service });
5858
const resp = await client.request(
5959
subject,
6060
{ name, args },

src/packages/lite/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
"exports": {
66
"./*": "./dist/*.js"
77
},
8-
"keywords": [
9-
"lite",
10-
"cocalc"
11-
],
8+
"keywords": ["lite", "cocalc"],
129
"scripts": {
1310
"preinstall": "npx only-allow pnpm",
1411
"clean": "rm -rf build dist node_modules sea/sea-prep.blob",

0 commit comments

Comments
 (0)