|
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 |
@@ -114,7 +115,7 @@ async def get_body(request: Request): |
114 | 115 | "/get-online-features", |
115 | 116 | dependencies=[Depends(inject_user_details)], |
116 | 117 | ) |
117 | | - def get_online_features(body=Depends(get_body)): |
| 118 | + async def get_online_features(body=Depends(get_body)): |
118 | 119 | body = json.loads(body) |
119 | 120 | full_feature_names = body.get("full_feature_names", False) |
120 | 121 | entity_rows = body["entities"] |
@@ -147,15 +148,22 @@ def get_online_features(body=Depends(get_body)): |
147 | 148 | resource=od_feature_view, actions=[AuthzedAction.READ_ONLINE] |
148 | 149 | ) |
149 | 150 |
|
150 | | - response_proto = store.get_online_features( |
| 151 | + read_params = dict( |
151 | 152 | features=features, |
152 | 153 | entity_rows=entity_rows, |
153 | 154 | full_feature_names=full_feature_names, |
154 | | - ).proto |
| 155 | + ) |
| 156 | + |
| 157 | + if store._get_provider().async_supported.online.read: |
| 158 | + response = await store.get_online_features_async(**read_params) |
| 159 | + else: |
| 160 | + response = await run_in_threadpool( |
| 161 | + lambda: store.get_online_features(**read_params) |
| 162 | + ) |
155 | 163 |
|
156 | 164 | # Convert the Protobuf object to JSON and return it |
157 | 165 | return MessageToDict( |
158 | | - response_proto, preserving_proto_field_name=True, float_precision=18 |
| 166 | + response.proto, preserving_proto_field_name=True, float_precision=18 |
159 | 167 | ) |
160 | 168 |
|
161 | 169 | @app.post("/push", dependencies=[Depends(inject_user_details)]) |
|
0 commit comments