Skip to content
Snippets Groups Projects
Commit dc70f847 authored by Neda Moeini's avatar Neda Moeini
Browse files

Used Threads to perform concurrent tasks in getting routers from WFO.

parent e30927ac
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment