From 3fec93d973bbf0fef38939cd230ac3a98d0aca10 Mon Sep 17 00:00:00 2001 From: Neda Moeini <neda.moeini@geant.org> Date: Mon, 24 Jun 2024 16:28:27 +0200 Subject: [PATCH] Used Threads to perform concurrent tasks in getting routers from WFO. --- inventory_provider/gap.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/inventory_provider/gap.py b/inventory_provider/gap.py index bd91ea5f..b4333fa9 100644 --- a/inventory_provider/gap.py +++ b/inventory_provider/gap.py @@ -1,7 +1,9 @@ import logging +import time import requests from flask import current_app +import concurrent.futures logger = logging.getLogger(__name__) @@ -110,14 +112,16 @@ def load_routers_from_orchestrator() -> dict: """ routers = {} response = make_request(body={'query': query}) - + print(time.time()) try: devices = response['data']['subscriptions']['page'] except (TypeError, KeyError): devices = [] - for device in devices: - router_info = extract_router_info(device) - if router_info is not None: - routers[router_info['fqdn']] = router_info['vendor'] + with concurrent.futures.ThreadPoolExecutor() as executor: + futures = [executor.submit(extract_router_info, device) for device in devices] + for future in concurrent.futures.as_completed(futures): + router_info = future.result() + if router_info is not None: + routers[router_info['fqdn']] = router_info['vendor'] return routers -- GitLab