Spaces:
Sleeping
Sleeping
Update api/endpoints/location.py
Browse files- api/endpoints/location.py +12 -6
api/endpoints/location.py
CHANGED
|
@@ -28,13 +28,19 @@ async def get_coordinates_v1(cord):
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
async def process_coordinates(supabase_user_data, max_concurrency=15):
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
async with semaphore:
|
| 35 |
-
return await get_coordinates_v1(cord)
|
| 36 |
-
|
| 37 |
-
coords = await asyncio.gather(*[bounded_get_coordinates(cord) for cord in supabase_user_data])
|
| 38 |
return [coord for coord in coords if coord is not None]
|
| 39 |
|
| 40 |
@router.post("/get_coordinates")
|
|
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
async def process_coordinates(supabase_user_data, max_concurrency=15):
|
| 31 |
+
coords=[]
|
| 32 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 33 |
+
futures = {executor.submit(LocationService.get_coordinates,cord): cord for cord in supabase_user_data}
|
| 34 |
+
for future in concurrent.futures.as_completed(futures):
|
| 35 |
+
task_name = futures[future]
|
| 36 |
+
try:
|
| 37 |
+
result = future.result()
|
| 38 |
+
coords.append(result)
|
| 39 |
+
print(f"{task_name} completed with result: {result}")
|
| 40 |
+
except Exception as exc:
|
| 41 |
+
print(f"{task_name} generated an exception: {exc}")
|
| 42 |
|
| 43 |
+
# coords = await asyncio.gather(*[bounded_get_coordinates(cord) for cord in supabase_user_data])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return [coord for coord in coords if coord is not None]
|
| 45 |
|
| 46 |
@router.post("/get_coordinates")
|