99from collections .abc import Iterable
1010from packaging .version import Version
1111from ray .serve import shutdown
12+ from ray .serve .handle import DeploymentHandle
1213from typing import Dict , List , Optional
1314
1415from .schema import schema as default_schema
1516
1617logger = logging .getLogger (__name__ )
1718
18- __all__ = ("AsyncMetadataTracker" , "RayTaskTracker" )
19+ __all__ = ("AsyncMetadataTracker" , "RayTaskTracker" , "setup_proxy_server" )
1920
2021
2122def get_callback_actor_name (name : str ) -> str :
2223 return f"{ name } _callback_actor"
2324
2425
26+ def setup_proxy_server (proxy_server_name = "proxy" , proxy_server_route_prefix = "/proxy" , ** kwargs ) -> DeploymentHandle :
27+ """Construct a webserver, and bind it to a PerspectiveProxyRayServer.
28+
29+ Args:
30+ proxy_server_name: the name passed to ray.serve.run for the PerspectiveProxyRayServer
31+ proxy_server_route_prefix: the route_prefix passed to ray.serve.run for the PerspectiveProxyRayServer
32+ **kwargs: arguments forwarded to ray.serve.run() for the webserver
33+
34+ Returns: A DeploymentHandle for the PerspectiveProxyRayServer
35+ """
36+ from raydar .dashboard .server import PerspectiveProxyRayServer
37+
38+ webserver = ray .serve .run (** kwargs )
39+ proxy_server = ray .serve .run (
40+ PerspectiveProxyRayServer .bind (webserver ),
41+ name = proxy_server_name ,
42+ route_prefix = proxy_server_route_prefix ,
43+ )
44+ return proxy_server
45+
46+
2547@ray .remote (resources = {"node:__internal_head__" : 0.1 }, num_cpus = 0 )
2648class AsyncMetadataTrackerCallback :
2749 """
@@ -107,22 +129,18 @@ def __init__(
107129 self .client = StateApiClient (address = ray .get_runtime_context ().gcs_address )
108130
109131 if self .perspective_dashboard_enabled :
110- from raydar .dashboard .server import PerspectiveProxyRayServer , PerspectiveRayServer
132+ from raydar .dashboard .server import PerspectiveRayServer
111133
112134 kwargs = dict (
113135 target = PerspectiveRayServer .bind (),
114136 name = "webserver" ,
115137 route_prefix = "/" ,
116138 )
139+
117140 if Version (ray .__version__ ) < Version ("2.10" ):
118141 kwargs ["port" ] = os .environ .get ("RAYDAR_PORT" , 8000 )
119142
120- self .webserver = ray .serve .run (** kwargs )
121- self .proxy_server = ray .serve .run (
122- PerspectiveProxyRayServer .bind (self .webserver ),
123- name = "proxy" ,
124- route_prefix = "/proxy" ,
125- )
143+ self .proxy_server = setup_proxy_server (** kwargs )
126144 self .proxy_server .remote (
127145 "new" ,
128146 self .perspective_table_name ,
@@ -149,14 +167,6 @@ def __init__(
149167 },
150168 )
151169
152- def get_proxy_server (self ) -> ray .serve .handle .DeploymentHandle :
153- """A getter for this actors proxy server attribute. Can be used to create custom perspective visuals.
154- Returns: this actors proxy_server attribute
155- """
156- if self .proxy_server :
157- return self .proxy_server
158- raise Exception ("This task_tracker has no active proxy_server." )
159-
160170 def callback (self , tasks : Iterable [ray .ObjectRef ]) -> None :
161171 """A remote function used by this actor's processor actor attribute. Will be called by a separate actor
162172 with a collection of ray object references once those ObjectReferences are not in the "RUNNING" or
@@ -287,6 +297,14 @@ def get_df(self) -> pl.DataFrame:
287297 )
288298 return self .df
289299
300+ def get_proxy_server (self ) -> ray .serve .handle .DeploymentHandle :
301+ """A getter for this actors proxy server attribute. Can be used to create custom perspective visuals.
302+ Returns: this actors proxy_server attribute
303+ """
304+ if self .proxy_server :
305+ return self .proxy_server
306+ raise Exception ("This task_tracker has no active proxy_server." )
307+
290308 def save_df (self ) -> None :
291309 """Saves the internally maintained dataframe of task related information from the ray GCS"""
292310 self .get_df ()
0 commit comments