Skip to content

Commit 88c7216

Browse files
committed
Resolve the proxy separately for refresh component
Signed-off-by: Joe Friedrichsen <[email protected]>
1 parent 7af7a9b commit 88c7216

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
"""Initializes a refresh component for Streamlit."""
22

3+
from typing import ClassVar
4+
5+
from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
6+
from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool
37
from streamlit.components.v1 import declare_component
48
from streamlit.components.v1.custom_component import CustomComponent
59

610

11+
class _ServiceResolver:
12+
13+
_panel_service_proxy_location: ClassVar[str | None] = None
14+
15+
@classmethod
16+
def get_or_resolve_proxy(cls) -> str:
17+
if cls._panel_service_proxy_location is None:
18+
discovery_client = DiscoveryClient(grpc_channel_pool=GrpcChannelPool())
19+
service_location = discovery_client.resolve_service(
20+
provided_interface="ni.http1.proxy",
21+
service_class="",
22+
)
23+
cls._panel_service_proxy_location = service_location.insecure_address
24+
25+
return cls._panel_service_proxy_location
26+
27+
728
def initialize_refresh_component(panel_id: str) -> CustomComponent:
829
"""Initialize a refresh component to the Streamlit app."""
9-
proxy_url = "TODO"
30+
proxy_base_address = _ServiceResolver.get_or_resolve_proxy()
31+
component_url = f"http://{proxy_base_address}/panel-service/refresh/{panel_id}"
1032
_refresh_component_func = declare_component(
1133
"panelRefreshComponent",
12-
url=f"http://{proxy_url}/panel-service/refresh/{panel_id}",
34+
url=component_url,
1335
)
1436

1537
return _refresh_component_func

0 commit comments

Comments
 (0)