From a47aa21e8465f78176d26305c77e06a28c2f4fe9 Mon Sep 17 00:00:00 2001 From: Alputer Date: Thu, 21 Nov 2024 23:03:55 +0100 Subject: [PATCH] feat(config): add get_dask_component_names function (#478) Closes reanahub/reana#841 --- reana_commons/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reana_commons/utils.py b/reana_commons/utils.py index 16051681..9443b5f8 100644 --- a/reana_commons/utils.py +++ b/reana_commons/utils.py @@ -414,6 +414,23 @@ def build_unique_component_name(component_type, id=None): ) +def get_dask_component_name(workflow_id, name_type): + """Generate the name of a Dask-related object based on the workflow ID and name type.""" + name_map = { + "cluster": f"reana-dask-{workflow_id}", + "autoscaler": f"dask-autoscaler-{workflow_id}", + "dashboard_ingress": f"dask-dashboard-ingress-{workflow_id}", + "dashboard_service": f"reana-dask-{workflow_id}-scheduler", + "dashboard_ingress_middleware": f"dask-dashboard-ingress-{workflow_id}-replacepath", + "db_service": f"dask-service-{workflow_id}", + } + if name_type not in name_map: + raise ValueError( + f"Invalid name type: '{name_type}'. Valid types are: {', '.join(name_map.keys())}." + ) + return name_map[name_type] + + def get_usage_percentage(usage: int, limit: int) -> str: """Usage percentage.""" if limit == 0: