|
10 | 10 | import psutil |
11 | 11 | from dateutil import parser |
12 | 12 | from fastapi import Depends, FastAPI, Request, Response, status |
| 13 | +from fastapi.concurrency import run_in_threadpool |
13 | 14 | from fastapi.logger import logger |
14 | 15 | from fastapi.responses import JSONResponse |
15 | 16 | from google.protobuf.json_format import MessageToDict |
@@ -112,7 +113,7 @@ async def get_body(request: Request): |
112 | 113 | "/get-online-features", |
113 | 114 | dependencies=[Depends(inject_user_details)], |
114 | 115 | ) |
115 | | - def get_online_features(body=Depends(get_body)): |
| 116 | + async def get_online_features(body=Depends(get_body)): |
116 | 117 | body = json.loads(body) |
117 | 118 | full_feature_names = body.get("full_feature_names", False) |
118 | 119 | entity_rows = body["entities"] |
@@ -145,15 +146,22 @@ def get_online_features(body=Depends(get_body)): |
145 | 146 | resource=od_feature_view, actions=[AuthzedAction.READ_ONLINE] |
146 | 147 | ) |
147 | 148 |
|
148 | | - response_proto = store.get_online_features( |
| 149 | + read_params = dict( |
149 | 150 | features=features, |
150 | 151 | entity_rows=entity_rows, |
151 | 152 | full_feature_names=full_feature_names, |
152 | | - ).proto |
| 153 | + ) |
| 154 | + |
| 155 | + if store._get_provider().async_supported.online.read: |
| 156 | + response = await store.get_online_features_async(**read_params) |
| 157 | + else: |
| 158 | + response = await run_in_threadpool( |
| 159 | + lambda: store.get_online_features(**read_params) |
| 160 | + ) |
153 | 161 |
|
154 | 162 | # Convert the Protobuf object to JSON and return it |
155 | 163 | return MessageToDict( |
156 | | - response_proto, preserving_proto_field_name=True, float_precision=18 |
| 164 | + response.proto, preserving_proto_field_name=True, float_precision=18 |
157 | 165 | ) |
158 | 166 |
|
159 | 167 | @app.post("/push", dependencies=[Depends(inject_user_details)]) |
|
0 commit comments