Commit 233812094961ae2990151234fde8e10c8443ed18

Authored by Antoine Goutenoir
1 parent 78eb2a62
Exists in master

Skip repeated failures gracefully.

Showing 1 changed file with 9 additions and 0 deletions   Show diff stats
flaskr/controllers/main_controller.py
@@ -269,6 +269,7 @@ def compute(): # process the queue of estimation requests @@ -269,6 +269,7 @@ def compute(): # process the queue of estimation requests
269 estimation.public_id 269 estimation.public_id
270 ) 270 )
271 271
  272 + failed_addresses = []
272 geocoder = CachedGeocoder() 273 geocoder = CachedGeocoder()
273 274
274 # GEOCODE ORIGINS ######################################################### 275 # GEOCODE ORIGINS #########################################################
@@ -279,6 +280,8 @@ def compute(): # process the queue of estimation requests @@ -279,6 +280,8 @@ def compute(): # process the queue of estimation requests
279 for i in range(len(origins_addresses)): 280 for i in range(len(origins_addresses)):
280 281
281 origin_address = origins_addresses[i].strip() 282 origin_address = origins_addresses[i].strip()
  283 + if origin_address in failed_addresses:
  284 + continue
282 285
283 try: 286 try:
284 origin = geocoder.geocode(origin_address.encode('utf-8')) 287 origin = geocoder.geocode(origin_address.encode('utf-8'))
@@ -287,6 +290,7 @@ def compute(): # process the queue of estimation requests @@ -287,6 +290,7 @@ def compute(): # process the queue of estimation requests
287 origin_address, e, 290 origin_address, e,
288 ) 291 )
289 _handle_warning(estimation, response) 292 _handle_warning(estimation, response)
  293 + failed_addresses.append(origin_address)
290 continue 294 continue
291 295
292 if origin is None: 296 if origin is None:
@@ -294,6 +298,7 @@ def compute(): # process the queue of estimation requests @@ -294,6 +298,7 @@ def compute(): # process the queue of estimation requests
294 origin_address, 298 origin_address,
295 ) 299 )
296 _handle_warning(estimation, response) 300 _handle_warning(estimation, response)
  301 + failed_addresses.append(origin_address)
297 continue 302 continue
298 303
299 origins.append(origin) 304 origins.append(origin)
@@ -311,6 +316,8 @@ def compute(): # process the queue of estimation requests @@ -311,6 +316,8 @@ def compute(): # process the queue of estimation requests
311 for i in range(len(destinations_addresses)): 316 for i in range(len(destinations_addresses)):
312 317
313 destination_address = destinations_addresses[i].strip() 318 destination_address = destinations_addresses[i].strip()
  319 + if destination_address in failed_addresses:
  320 + continue
314 321
315 try: 322 try:
316 destination = geocoder.geocode(destination_address.encode('utf-8')) 323 destination = geocoder.geocode(destination_address.encode('utf-8'))
@@ -319,6 +326,7 @@ def compute(): # process the queue of estimation requests @@ -319,6 +326,7 @@ def compute(): # process the queue of estimation requests
319 destination_address, e, 326 destination_address, e,
320 ) 327 )
321 _handle_warning(estimation, response) 328 _handle_warning(estimation, response)
  329 + failed_addresses.append(destination_address)
322 continue 330 continue
323 331
324 if destination is None: 332 if destination is None:
@@ -326,6 +334,7 @@ def compute(): # process the queue of estimation requests @@ -326,6 +334,7 @@ def compute(): # process the queue of estimation requests
326 destination_address, 334 destination_address,
327 ) 335 )
328 _handle_warning(estimation, response) 336 _handle_warning(estimation, response)
  337 + failed_addresses.append(destination_address)
329 continue 338 continue
330 339
331 # print(repr(destination.raw)) 340 # print(repr(destination.raw))