Skip to content

Commit

Permalink
feat: expose the service url as a property
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed May 14, 2024
1 parent 3c33b4d commit 246e03c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/_bentoml_impl/server/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def serve_http(
)

log_host = "localhost" if host in ["0.0.0.0", "::"] else host
dependency_map[svc.name] = f"{scheme}://{log_host}:{port}"

# inject runner map now
inject_env = {"BENTOML_RUNNER_MAP": json.dumps(dependency_map)}
Expand Down
7 changes: 7 additions & 0 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def find_dependent(self, name_or_path: str) -> Service[t.Any]:
return self.dependencies[attr_name].on.find_dependent(path)
return self.dependencies[attr_name].on

@property
def url(self) -> str | None:
"""Get the URL of the service, or None if the service is not served"""
dependency_map = BentoMLContainer.remote_runner_mapping.get()
url = dependency_map.get(self.name)
return url.replace("tcp://", "http://") if url else None

@lru_cache(maxsize=1)
def all_services(self) -> dict[str, Service[t.Any]]:
"""Get a map of the service and all recursive dependencies"""
Expand Down

0 comments on commit 246e03c

Please sign in to comment.