1
1
import asyncio
2
+ import json
2
3
import os
3
4
import queue
4
5
import sys
5
6
import traceback
6
7
from copy import deepcopy
7
8
from multiprocessing import Queue
9
+ from pathlib import Path
8
10
from tempfile import TemporaryDirectory
9
11
from threading import Event , Lock , Thread
10
12
from time import sleep
@@ -68,6 +70,7 @@ class SessionMiddleware:
68
70
69
71
app_spec : Optional [List ] = None
70
72
app_status : Optional [AppStatus ] = None
73
+ app_annotations : Optional [List ] = None
71
74
72
75
# In the future, this would be abstracted to support horizontal scaling.
73
76
responses_store = {}
@@ -345,6 +348,13 @@ async def get_status() -> AppStatus:
345
348
return app_status
346
349
347
350
351
+ @fastapi_service .get ("/api/v1/annotations" , response_class = JSONResponse )
352
+ async def get_annotations () -> Union [List , Dict ]:
353
+ """Get the annotations associated with this app."""
354
+ global app_annotations
355
+ return app_annotations or []
356
+
357
+
348
358
@fastapi_service .get ("/healthz" , status_code = 200 )
349
359
async def healthz (response : Response ):
350
360
"""Health check endpoint used in the cloud FastAPI servers to check the status periodically."""
@@ -440,6 +450,7 @@ def start_server(
440
450
global api_app_delta_queue
441
451
global global_app_state_store
442
452
global app_spec
453
+ global app_annotations
443
454
444
455
app_spec = spec
445
456
api_app_delta_queue = api_delta_queue
@@ -449,6 +460,12 @@ def start_server(
449
460
450
461
global_app_state_store .add (TEST_SESSION_UUID )
451
462
463
+ # Load annotations
464
+ annotations_path = Path ("lightning-annotations.json" ).resolve ()
465
+ if annotations_path .exists ():
466
+ with open (annotations_path ) as f :
467
+ app_annotations = json .load (f )
468
+
452
469
refresher = UIRefresher (api_publish_state_queue , api_response_queue )
453
470
refresher .setDaemon (True )
454
471
refresher .start ()
0 commit comments