77
88logger = logging .getLogger (__name__ )
99
10+
1011class XDMoDConnectivityError (Exception ):
1112 pass
1213
14+
1315class XDMoDFetchError (Exception ):
1416 pass
1517
18+
1619def _worker (q : Queue , url : str , metric : str , account : str ) -> None :
1720 try :
1821 # Construct inside the worker so we don't share sockets across processes
@@ -29,6 +32,7 @@ def _worker(q: Queue, url: str, metric: str, account: str) -> None:
2932 # Send back a lightweight, picklable error payload
3033 q .put (("err" , (e .__class__ .__name__ , str (e ))))
3134
35+
3236def fetch_xdmod_with_timeout (url : str , metric : str , account : str , timeout_s : float = 15.0 ):
3337 q : Queue = Queue ()
3438 p = Process (target = _worker , args = (q , url , metric , account ))
@@ -55,6 +59,7 @@ def fetch_xdmod_with_timeout(url: str, metric: str, account: str, timeout_s: flo
5559 raise XDMoDConnectivityError (f"XDMoD get_data timeout: { exc_msg } " )
5660 raise XDMoDFetchError (f"XDMoD get_data error: { exc_name } : { exc_msg } " )
5761
62+
5863def check_connectivity (url : str , timeout : float = 5.0 ) -> None :
5964 from urllib .parse import urlparse
6065 import requests
@@ -72,22 +77,15 @@ def check_connectivity(url: str, timeout: float = 5.0) -> None:
7277 except requests .exceptions .RequestException as e :
7378 raise XDMoDConnectivityError (str (e )) from e
7479
80+
7581def get_usage_data (_metric : str , _slurm_acccount_name : str ):
7682 logger .info (
77- f"attempting to fetch usage \
83+ f"attempting to fetch { _metric } data \
7884 associated with { _slurm_acccount_name } "
7985 )
8086 try :
8187 check_connectivity (XDMOD_API_URL )
82- dw = DataWarehouse (XDMOD_API_URL )
83- with dw :
84- data = fetch_xdmod_with_timeout (
85- XDMOD_API_URL ,
86- metric = _metric ,
87- account = _slurm_acccount_name ,
88- timeout_s = 15.0
89- )
90- return data
88+ return fetch_xdmod_with_timeout (XDMOD_API_URL , metric = _metric , account = _slurm_acccount_name , timeout_s = 15.0 )
9189 except XDMoDConnectivityError as e :
9290 logger .error ("XDMOD connectivity error: %s" , e )
9391 raise XDMoDConnectivityError (str (e )) from e
0 commit comments