11import json
22import logging
3- import threading
43from importlib import resources as importlib_resources
5- from typing import Callable , Optional
64
75import uvicorn
86from fastapi import FastAPI , Response , status
@@ -21,23 +19,23 @@ def _build_projects_list(
2119):
2220 """Build the projects list for the UI."""
2321 discovered_projects = []
24- registry = store .registry .proto ()
25-
2622 registry_path_template = f"{ root_path } /api/v1"
2723
28- if registry and registry .projects and len (registry .projects ) > 0 :
29- for proj in registry .projects :
30- if proj .spec and proj .spec .name :
31- discovered_projects .append (
32- {
33- "name" : proj .spec .name .replace ("_" , " " ).title (),
34- "description" : proj .spec .description
35- or f"Project: { proj .spec .name } " ,
36- "id" : proj .spec .name ,
37- "registryPath" : registry_path_template ,
38- }
39- )
40- else :
24+ try :
25+ projects = store .registry .list_projects (allow_cache = True )
26+ for proj in projects :
27+ discovered_projects .append (
28+ {
29+ "name" : proj .name .replace ("_" , " " ).title (),
30+ "description" : proj .description or f"Project: { proj .name } " ,
31+ "id" : proj .name ,
32+ "registryPath" : registry_path_template ,
33+ }
34+ )
35+ except Exception :
36+ pass
37+
38+ if not discovered_projects :
4139 discovered_projects .append (
4240 {
4341 "name" : "Project" ,
@@ -59,34 +57,11 @@ def _build_projects_list(
5957 return {"projects" : discovered_projects }
6058
6159
62- def _setup_rest_mode (app : FastAPI , store : "feast.FeatureStore" , registry_ttl_secs : int ):
60+ def _setup_rest_mode (app : FastAPI , store : "feast.FeatureStore" ):
6361 """Mount the REST registry API routes on the UI server under /api/v1."""
6462 from feast .api .registry .rest import register_all_routes
6563 from feast .registry_server import RegistryServer
6664
67- registry_proto = None
68- shutting_down = False
69- active_timer : Optional [threading .Timer ] = None
70-
71- def async_refresh ():
72- store .refresh_registry ()
73- nonlocal registry_proto
74- registry_proto = store .registry .proto ()
75- if shutting_down :
76- return
77- nonlocal active_timer
78- active_timer = threading .Timer (registry_ttl_secs , async_refresh )
79- active_timer .start ()
80-
81- @app .on_event ("shutdown" )
82- def shutdown_event ():
83- nonlocal shutting_down
84- shutting_down = True
85- if active_timer :
86- active_timer .cancel ()
87-
88- async_refresh ()
89-
9065 grpc_handler = RegistryServer (store .registry )
9166
9267 rest_app = FastAPI (root_path = "/api/v1" )
@@ -95,19 +70,18 @@ def shutdown_event():
9570
9671 @app .get ("/health" )
9772 def health ():
98- return (
99- Response ( status_code = status . HTTP_200_OK )
100- if registry_proto
101- else Response ( status_code = status . HTTP_503_SERVICE_UNAVAILABLE )
102- )
73+ try :
74+ store . registry . list_projects ( allow_cache = True )
75+ return Response ( status_code = status . HTTP_200_OK )
76+ except Exception :
77+ return Response ( status_code = status . HTTP_503_SERVICE_UNAVAILABLE )
10378
10479 logger .info ("REST registry API mounted at /api/v1" )
10580
10681
10782def get_app (
10883 store : "feast.FeatureStore" ,
10984 project_id : str ,
110- registry_ttl_secs : int ,
11185 root_path : str = "" ,
11286):
11387 app = FastAPI ()
@@ -120,7 +94,7 @@ def get_app(
12094 allow_headers = ["*" ],
12195 )
12296
123- _setup_rest_mode (app , store , registry_ttl_secs )
97+ _setup_rest_mode (app , store )
12498
12599 ui_dir_ref = importlib_resources .files (__spec__ .parent ) / "ui/build/" # type: ignore[name-defined, arg-type]
126100 with importlib_resources .as_file (ui_dir_ref ) as ui_dir :
@@ -148,17 +122,14 @@ def start_server(
148122 store : "feast.FeatureStore" ,
149123 host : str ,
150124 port : int ,
151- get_registry_dump : Callable ,
152125 project_id : str ,
153- registry_ttl_sec : int ,
154126 root_path : str = "" ,
155127 tls_key_path : str = "" ,
156128 tls_cert_path : str = "" ,
157129):
158130 app = get_app (
159131 store ,
160132 project_id ,
161- registry_ttl_sec ,
162133 root_path ,
163134 )
164135
0 commit comments