Commit 92abc15ba3dbfb7f133b7725ec4cfafa778bd329

Authored by Goutte
1 parent 3d597f3f

Mistrust the API some more.

Showing 1 changed file with 10 additions and 6 deletions   Show diff stats
@@ -197,6 +197,7 @@ def retrieve_data(orbiter, what, started_at, stopped_at): @@ -197,6 +197,7 @@ def retrieve_data(orbiter, what, started_at, stopped_at):
197 log.info("Fetching remote gzip files list at '%s'." % url) 197 log.info("Fetching remote gzip files list at '%s'." % url)
198 retries = 0 198 retries = 0
199 success = False 199 success = False
  200 + errors = []
200 remote_gzip_files = [] 201 remote_gzip_files = []
201 while not success and retries < 3: 202 while not success and retries < 3:
202 try: 203 try:
@@ -205,18 +206,20 @@ def retrieve_data(orbiter, what, started_at, stopped_at): @@ -205,18 +206,20 @@ def retrieve_data(orbiter, what, started_at, stopped_at):
205 if not remote_gzip_files: 206 if not remote_gzip_files:
206 raise Exception("Failed to fetch data at '%s'." % url) 207 raise Exception("Failed to fetch data at '%s'." % url)
207 if remote_gzip_files == 'NODATASET': 208 if remote_gzip_files == 'NODATASET':
208 - raise Exception("No dataset at '%s'." % url) 209 + raise Exception("API says there's no dataset at '%s'." % url)
  210 + if remote_gzip_files == 'ERROR':
  211 + raise Exception("API returned an error at '%s'." % url)
  212 + if remote_gzip_files == ['OUTOFTIME']:
  213 + raise Exception("API says it's out of time at '%s'." % url)
209 success = True 214 success = True
210 except Exception as e: 215 except Exception as e:
211 log.warn("Failed (%d/3) '%s' : %s" % (retries+1, url, e.message)) 216 log.warn("Failed (%d/3) '%s' : %s" % (retries+1, url, e.message))
  217 + remote_gzip_files = []
  218 + errors.append(e)
212 finally: 219 finally:
213 retries += 1 220 retries += 1
214 if not remote_gzip_files: 221 if not remote_gzip_files:
215 - abort(400, "Failed to fetch data at '%s'." % url)  
216 - if remote_gzip_files == 'NODATASET':  
217 - abort(400, "No dataset at '%s'." % url)  
218 - # if remote_gzip_files == ['OUTOFTIME']:  
219 - # abort(400, "No data for time interval at '%s'." % url) 222 + abort(400, "Failed to fetch data at '%s' : %s" % (url, errors))
220 223
221 log.debug("Fetched remote gzip files list : %s." % str(remote_gzip_files)) 224 log.debug("Fetched remote gzip files list : %s." % str(remote_gzip_files))
222 225
@@ -352,6 +355,7 @@ def generate_csv_file_if_needed(target_config, started_at, stopped_at): @@ -352,6 +355,7 @@ def generate_csv_file_if_needed(target_config, started_at, stopped_at):
352 log.info("Generation of '%s' done." % filename) 355 log.info("Generation of '%s' done." % filename)
353 except Exception as e: 356 except Exception as e:
354 if isfile(local_csv_file): 357 if isfile(local_csv_file):
  358 + log.warn("Removing failed CSV '%s'..." % local_csv_file)
355 removefile(local_csv_file) 359 removefile(local_csv_file)
356 abort(500, "Failed creating CSV '%s' : %s" % (filename, e)) 360 abort(500, "Failed creating CSV '%s' : %s" % (filename, e))
357 361