Emulates the properties of the ray._private.worker object for the client
| 7 | |
| 8 | |
| 9 | class _ClientWorkerPropertyAPI: |
| 10 | """Emulates the properties of the ray._private.worker object for the client""" |
| 11 | |
| 12 | def __init__(self, worker): |
| 13 | assert worker is not None |
| 14 | self.worker = worker |
| 15 | |
| 16 | def build_runtime_context(self) -> "RuntimeContext": |
| 17 | """Creates a RuntimeContext backed by the properites of this API""" |
| 18 | # Defer the import of RuntimeContext until needed to avoid cycles |
| 19 | from ray.runtime_context import RuntimeContext |
| 20 | |
| 21 | return RuntimeContext(self) |
| 22 | |
| 23 | def _fetch_runtime_context(self): |
| 24 | import ray.core.generated.ray_client_pb2 as ray_client_pb2 |
| 25 | |
| 26 | return self.worker.get_cluster_info( |
| 27 | ray_client_pb2.ClusterInfoType.RUNTIME_CONTEXT |
| 28 | ) |
| 29 | |
| 30 | @property |
| 31 | def mode(self): |
| 32 | from ray._private.worker import SCRIPT_MODE |
| 33 | |
| 34 | return SCRIPT_MODE |
| 35 | |
| 36 | @property |
| 37 | def current_job_id(self) -> "JobID": |
| 38 | from ray import JobID |
| 39 | |
| 40 | return JobID(self._fetch_runtime_context().job_id) |
| 41 | |
| 42 | @property |
| 43 | def current_node_id(self) -> "NodeID": |
| 44 | from ray import NodeID |
| 45 | |
| 46 | return NodeID(self._fetch_runtime_context().node_id) |
| 47 | |
| 48 | @property |
| 49 | def worker_id(self) -> "WorkerID": |
| 50 | """Binary worker id for the Ray Client server process (cluster driver worker).""" |
| 51 | from ray import WorkerID |
| 52 | |
| 53 | return WorkerID(self._fetch_runtime_context().worker_id) |
| 54 | |
| 55 | @property |
| 56 | def namespace(self) -> str: |
| 57 | return self._fetch_runtime_context().namespace |
| 58 | |
| 59 | @property |
| 60 | def should_capture_child_tasks_in_placement_group(self) -> bool: |
| 61 | return self._fetch_runtime_context().capture_client_tasks |
| 62 | |
| 63 | @property |
| 64 | def runtime_env(self) -> str: |
| 65 | return self._fetch_runtime_context().runtime_env |
| 66 |
no outgoing calls
no test coverage detected
searching dependent graphs…