From 2752103a3d1f9449bcc49851af6374d7b238db21 Mon Sep 17 00:00:00 2001 From: Marco Lucarelli Date: Thu, 13 Nov 2025 13:14:05 +0100 Subject: [PATCH] test with redfish logout --- python/redfish-api/redfish_exporter.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/python/redfish-api/redfish_exporter.py b/python/redfish-api/redfish_exporter.py index 52ad180..538885c 100644 --- a/python/redfish-api/redfish_exporter.py +++ b/python/redfish-api/redfish_exporter.py @@ -269,16 +269,18 @@ async def run_exporter(config, stop_event): # Connection pooling with aiohttp connector = aiohttp.TCPConnector(limit_per_host=5, limit=50, ttl_dns_cache=300) async with aiohttp.ClientSession(connector=connector) as session: - hosts = [HostConfig(**h) for h in config["hosts"]] - while not stop_event.is_set(): - tasks = [get_power_data(session, hc) for hc in host_objs] - - await asyncio.gather(*tasks) - await process_request(interval) - # shutdown service + try: + while not stop_event.is_set(): + tasks = [get_power_data(session, hc) for hc in host_objs] + await asyncio.gather(*tasks) + await process_request(interval) + finally: + # Graceful shutdown: logout from Redfish sessions logging.info("Exporter stopping, logging out from Redfish sessions...") - await asyncio.gather(*(logout_host(session, h) for h in hosts if h.session_token)) - + await asyncio.gather( + *(logout_host(session, h) for h in host_objs if h.session_token) + ) + logging.info("All sessions logged out.") logging.info("Exporter stopped cleanly.")