@@ -7,13 +7,6 @@ server. It does the following:
7
7
8
8
- If id is as requested and is not the project, draw line in color of that compute server.
9
9
10
- - If not where we want to be, defines how close via a percentage
11
-
12
- - If compute server not running:
13
- - if exists and you own it, prompts user to start it and also shows the
14
- compute server's component so they can do so.
15
- - if not exists (or deleted), say so
16
- - if owned by somebody else, say so
17
10
*/
18
11
19
12
import Inline from "./inline" ;
@@ -29,6 +22,7 @@ import { avatar_fontcolor } from "@cocalc/frontend/account/avatar/font-color";
29
22
import { DisplayImage } from "./select-image" ;
30
23
import Menu from "./menu" ;
31
24
import { SpendLimitStatus } from "./spend-limit" ;
25
+ import useComputeServerApiState from "./use-compute-server-api-state" ;
32
26
33
27
interface Props {
34
28
project_id : string ;
@@ -48,6 +42,11 @@ export function ComputeServerDocStatus({
48
42
if ( requestedId == null ) {
49
43
requestedId = id ;
50
44
}
45
+ const apiState = useComputeServerApiState ( {
46
+ project_id,
47
+ compute_server_id : requestedId ,
48
+ } ) ;
49
+
51
50
const [ showDetails , setShowDetails ] = useState < boolean | null > ( null ) ;
52
51
const computeServers = useTypedRedux ( { project_id } , "compute_servers" ) ;
53
52
const account_id = useTypedRedux ( "account" , "account_id" ) ;
@@ -210,11 +209,15 @@ export function ComputeServerDocStatus({
210
209
const { progress, message, status } = getProgress (
211
210
server ,
212
211
account_id ,
213
- id ,
214
212
requestedId ,
213
+ apiState ,
215
214
) ;
216
215
if ( ! showDetails ) {
217
- if ( showDetails == null && progress < 100 ) {
216
+ if (
217
+ showDetails == null &&
218
+ progress < 100 &&
219
+ ( apiState != null || status == "exception" )
220
+ ) {
218
221
setShowDetails ( true ) ;
219
222
}
220
223
return topBar ( progress ) ;
@@ -283,34 +286,35 @@ export function ComputeServerDocStatus({
283
286
) ;
284
287
}
285
288
286
- const ENABLED = true ;
289
+ // gets progress of starting the compute server with given id and
290
+ // having it actively available to host this file.
287
291
288
- // gets progress of starting the compute server with given id and having it actively available to host this file.
289
292
function getProgress (
290
293
server : ComputeServerUserInfo | undefined ,
291
294
account_id ,
292
- id ,
293
295
requestedId ,
296
+ apiState ,
294
297
) : {
295
298
progress : number ;
296
299
message : string ;
297
300
status : "exception" | "active" | "normal" | "success" ;
298
301
} {
299
- if ( ENABLED ) {
300
- return {
301
- progress : 100 ,
302
- message : "Compute server is fully connected!" ,
303
- status : "success" ,
304
- } ;
305
- }
306
-
307
302
if ( requestedId == 0 ) {
308
303
return {
309
304
progress : 50 ,
310
305
message : "Moving back to project..." ,
311
306
status : "active" ,
312
307
} ;
313
308
}
309
+
310
+ if ( apiState == "running" ) {
311
+ return {
312
+ progress : 100 ,
313
+ message : "Compute server is fully connected!" ,
314
+ status : "success" ,
315
+ } ;
316
+ }
317
+
314
318
if ( server == null ) {
315
319
return {
316
320
progress : 0 ,
@@ -330,17 +334,26 @@ function getProgress(
330
334
if (
331
335
server . account_id != account_id &&
332
336
server . state != "running" &&
333
- server . state != "starting"
337
+ server . state != "starting" &&
338
+ ! server . configuration ?. allowCollaboratorControl
334
339
) {
335
340
return {
336
341
progress : 0 ,
337
342
message :
338
- "This is not your compute server, and it is not running. Only the owner of a compute server can start it." ,
343
+ "This is not your compute server, and it is not running. Only the owner of this compute server can start it." ,
339
344
status : "exception" ,
340
345
} ;
341
346
}
342
347
343
- // below here it isn't our server, it is running.
348
+ if ( apiState != null ) {
349
+ if ( apiState == "starting" ) {
350
+ return {
351
+ progress : 75 ,
352
+ message : "Compute server is starting." ,
353
+ status : "active" ,
354
+ } ;
355
+ }
356
+ }
344
357
345
358
if ( server . state == "deprovisioned" ) {
346
359
return {
@@ -381,62 +394,20 @@ function getProgress(
381
394
} ;
382
395
}
383
396
384
- // below it is running
385
- const computeIsLive = server . detailed_state ?. compute ?. state == "ready" ;
386
- if ( computeIsLive ) {
387
- if ( id == requestedId ) {
388
- return {
389
- progress : 100 ,
390
- message : "Compute server is fully connected!" ,
391
- status : "success" ,
392
- } ;
393
- } else {
394
- return {
395
- progress : 90 ,
396
- message :
397
- "Compute server is connected and should attach to this file soon..." ,
398
- status : "success" ,
399
- } ;
400
- }
401
- }
402
- const filesystemIsLive =
403
- server . detailed_state ?. [ "filesystem-sync" ] ?. state == "ready" ;
404
- const computeIsRecent = isRecent ( server . detailed_state ?. compute ?. time ) ;
405
- const filesystemIsRecent = isRecent (
406
- server . detailed_state ?. [ "filesystem-sync" ] ?. time ,
407
- ) ;
408
- if ( filesystemIsRecent ) {
409
- return {
410
- progress : 70 ,
411
- message : "Waiting for filesystem to connect." ,
412
- status : "normal" ,
413
- } ;
414
- }
415
- if ( filesystemIsLive ) {
416
- if ( computeIsRecent ) {
417
- return {
418
- progress : 80 ,
419
- message : "Waiting for compute to connect." ,
420
- status : "normal" ,
421
- } ;
422
- }
423
- }
424
-
425
397
return {
426
398
progress : 50 ,
427
- message :
428
- "Compute server is running, but filesystem and compute components aren't connected. Waiting..." ,
399
+ message : "Compute server is starting..." ,
429
400
status : "active" ,
430
401
} ;
431
402
}
432
403
433
404
// This is useful elsewhere to give a sense of how the compute server
434
405
// is doing as it progresses from running to really being fully available.
435
- function getRunningStatus ( server ) {
406
+ function getRunningStatus ( server , apiState ) {
436
407
if ( server == null ) {
437
408
return { progress : 0 , message : "Loading..." , status : "exception" } ;
438
409
}
439
- return getProgress ( server , webapp_client . account_id , server . id , server . id ) ;
410
+ return getProgress ( server , webapp_client . account_id , server . id , apiState ) ;
440
411
}
441
412
442
413
export function RunningProgress ( {
@@ -446,8 +417,12 @@ export function RunningProgress({
446
417
server : ComputeServerUserInfo | undefined ;
447
418
style ?;
448
419
} ) {
420
+ const apiState = useComputeServerApiState ( {
421
+ project_id : server ?. project_id ,
422
+ compute_server_id : server ?. id ,
423
+ } ) ;
449
424
const { progress, message } = useMemo ( ( ) => {
450
- return getRunningStatus ( server ) ;
425
+ return getRunningStatus ( server , apiState ) ;
451
426
} , [ server ] ) ;
452
427
453
428
return (
@@ -461,7 +436,3 @@ export function RunningProgress({
461
436
</ Tooltip >
462
437
) ;
463
438
}
464
-
465
- function isRecent ( expire = 0 ) {
466
- return Date . now ( ) - expire < 60 * 1000 ;
467
- }
0 commit comments