From 769bd1b1e3c0adf32d87033a92bee0a67094c4d5 Mon Sep 17 00:00:00 2001 From: spike Date: Sat, 29 Jan 2022 15:51:52 -0500 Subject: [PATCH 1/2] added a check to make sure server is alive before trying to download data --- getDataFRF.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/getDataFRF.py b/getDataFRF.py index eb7fe77..b3cb033 100644 --- a/getDataFRF.py +++ b/getDataFRF.py @@ -48,7 +48,7 @@ def gettime(allEpoch, epochStart, epochEnd, indexRef=0): finally: return idx -def getnc(dataLoc, callingClass, epoch1=0, epoch2=0, dtRound=60, cutrange=100000,**kwargs): +def getnc(dataLoc, callingClass, epoch1=0, epoch2=0, dtRound=60, cutrange=100000, **kwargs): """Function grabs the netCDF file interested. Responsible for drilling down to specific monthly file if applicable to speed things up. @@ -95,6 +95,8 @@ def getnc(dataLoc, callingClass, epoch1=0, epoch2=0, dtRound=60, cutrange=100000 if callingClass == 'getDataTestBed': # overwrite pName if calling for model data pName = u'cmtb' + assert os.system("ping -c 1 " + THREDDSloc) == 0, f"Not able to see {THREDDSloc) + # now set URL for netCDF file call, if start is None and end is None: ncfileURL = urljoin('[FillMismatch]'+THREDDSloc, pName, dataLoc) @@ -245,7 +247,7 @@ def __init__(self, d1, d2, **kwargs): self._comp_time() assert type(self.d2) == DT.datetime, 'd1 need to be in python "Datetime" data types' assert type(self.d1) == DT.datetime, 'd2 need to be in python "Datetime" data types' - + def _comp_time(self): """Test if times are backwards.""" assert self.d2 >= self.d1, 'finish time: end needs to be after start time: start' From 0613e0eee88b2a873122d10097a401368126f6b3 Mon Sep 17 00:00:00 2001 From: spike Date: Sat, 29 Jan 2022 15:56:35 -0500 Subject: [PATCH 2/2] changed the logic to return a connection error, instead of a assertion error. This will allow for it to be handled downstream as needed, more effectively? : : --- getDataFRF.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/getDataFRF.py b/getDataFRF.py index b3cb033..3b5f81c 100644 --- a/getDataFRF.py +++ b/getDataFRF.py @@ -95,7 +95,8 @@ def getnc(dataLoc, callingClass, epoch1=0, epoch2=0, dtRound=60, cutrange=100000 if callingClass == 'getDataTestBed': # overwrite pName if calling for model data pName = u'cmtb' - assert os.system("ping -c 1 " + THREDDSloc) == 0, f"Not able to see {THREDDSloc) + if os.system("ping -c 1 " + THREDDSloc) ~= 0: + return ConnectionError(f"Not able to see {THREDDSloc)) # now set URL for netCDF file call, if start is None and end is None: