File tree Expand file tree Collapse file tree 3 files changed +15
-16
lines changed Expand file tree Collapse file tree 3 files changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface ProjectApi {
10
10
editor : Editor ;
11
11
jupyter : Jupyter ;
12
12
sync : Sync ;
13
+ isRunning : ( ) => Promise < boolean > ;
13
14
}
14
15
15
16
const ProjectApiStructure = {
@@ -19,7 +20,7 @@ const ProjectApiStructure = {
19
20
sync,
20
21
} as const ;
21
22
22
- export function initProjectApi ( callProjectApi ) : ProjectApi {
23
+ export function initProjectApi ( callProjectApi , isRunning ) : ProjectApi {
23
24
const projectApi : any = { } ;
24
25
for ( const group in ProjectApiStructure ) {
25
26
if ( projectApi [ group ] == null ) {
@@ -35,5 +36,6 @@ export function initProjectApi(callProjectApi): ProjectApi {
35
36
) ;
36
37
}
37
38
}
39
+ projectApi . isRunning = isRunning ;
38
40
return projectApi as ProjectApi ;
39
41
}
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { isValidUUID } from "@cocalc/util/misc";
8
8
import { type ProjectApi , initProjectApi } from "./index" ;
9
9
10
10
const DEFAULT_TIMEOUT = 15000 ;
11
+ const service = "api" ;
11
12
12
13
export function projectApiClient ( {
13
14
project_id,
@@ -23,38 +24,37 @@ export function projectApiClient({
23
24
if ( ! isValidUUID ( project_id ) ) {
24
25
throw Error ( `project_id = '${ project_id } ' must be a valid uuid` ) ;
25
26
}
27
+ const subject = projectSubject ( { project_id, compute_server_id, service } ) ;
28
+
29
+ const isRunning = async ( ) => {
30
+ return await client . interest ( subject ) ;
31
+ } ;
32
+
26
33
const callProjectApi = async ( { name, args } ) => {
27
34
return await callProject ( {
28
35
client,
29
- project_id,
30
- compute_server_id,
36
+ subject,
31
37
timeout,
32
- service : "api" ,
33
38
name,
34
39
args,
35
40
} ) ;
36
41
} ;
37
- return initProjectApi ( callProjectApi ) ;
42
+ return initProjectApi ( callProjectApi , isRunning ) ;
38
43
}
39
44
40
45
async function callProject ( {
41
46
client,
42
- service = "api" ,
43
- project_id,
44
- compute_server_id,
47
+ subject,
45
48
name,
46
49
args = [ ] ,
47
50
timeout = DEFAULT_TIMEOUT ,
48
51
} : {
49
52
client : Client ;
50
- service ?: string ;
51
- project_id : string ;
52
- compute_server_id ?: number ;
53
+ subject : string ;
53
54
name : string ;
54
55
args : any [ ] ;
55
56
timeout ?: number ;
56
57
} ) {
57
- const subject = projectSubject ( { project_id, compute_server_id, service } ) ;
58
58
const resp = await client . request (
59
59
subject ,
60
60
{ name, args } ,
Original file line number Diff line number Diff line change 5
5
"exports" : {
6
6
"./*" : " ./dist/*.js"
7
7
},
8
- "keywords" : [
9
- " lite" ,
10
- " cocalc"
11
- ],
8
+ "keywords" : [" lite" , " cocalc" ],
12
9
"scripts" : {
13
10
"preinstall" : " npx only-allow pnpm" ,
14
11
"clean" : " rm -rf build dist node_modules sea/sea-prep.blob" ,
You can’t perform that action at this time.
0 commit comments