2020
2121from decisionengine .framework .modules import Source
2222from decisionengine .framework .modules .Source import Parameter
23+ from decisionengine_modules .util .retry_function import retry_wrapper
2324
25+ _MAX_RETRIES = 50
26+ _RETRY_TIMEOUT = 30
2427
25- @Source .supports_config (Parameter ("constraints" , type = dict , comment = """Supports the layout:""" ))
28+ @Source .supports_config (
29+ Parameter ("constraints" , type = dict , comment = """Supports the layout:""" ),
30+ Parameter ("max_retries" , default = _MAX_RETRIES ),
31+ Parameter ("retry_timeout" , default = _RETRY_TIMEOUT ),
32+ )
2633@Source .produces (Nersc_Allocation_SFAPI = pd .DataFrame )
2734class NerscSFApi (Source .Source ):
2835 def __init__ (self , config ):
@@ -31,6 +38,8 @@ def __init__(self, config):
3138 self .constraints = config .get ("constraints" )
3239 if not isinstance (self .constraints , dict ):
3340 raise RuntimeError ("constraints should be a dict" )
41+ self .max_retries = config .get ("max_retries" , _MAX_RETRIES )
42+ self .retry_timeout = config .get ("retry_timeout" , _RETRY_TIMEOUT )
3443
3544 self .logger = self .logger .bind (
3645 class_module = __name__ .split ("." )[- 1 ],
@@ -148,6 +157,10 @@ def send_query(self):
148157
149158 def acquire (self ):
150159 self .logger .debug ("in NerscSFApi acquire" )
160+ return retry_wrapper (self ._acquire , self .max_retries , self .retry_timeout , backoff = False , logger = self .logger )
161+
162+ def _acquire (self ):
163+ self .logger .debug ("in NerscSFApi _acquire" )
151164 return {"Nersc_Allocation_SFAPI" : pd .DataFrame (self .send_query ())}
152165
153166
0 commit comments