2222_logger = logging .getLogger ("main" )
2323
2424
25- async def init_plugins_services (controller_enabled : bool , executor_enabled : bool ) -> None :
26- """Initialize the plugins services"""
27- for plugin_name , plugin in plugins .loaded_plugins .items ():
28- _logger .info (f"Loading plugin '{ plugin_name } '" )
29-
30- plugin_services = getattr (plugin , "services" , None )
31- if plugin_services is None :
32- _logger .info (f"Plugin '{ plugin_name } ' has no services" )
33- continue
34-
35- for service_name in plugin_services .__all__ :
36- service = getattr (plugin_services , service_name )
37- if hasattr (service , "init" ):
38- await service .init (controller_enabled , executor_enabled )
39- _logger .info (f"Service '{ plugin_name } .{ service_name } ' initialized" )
40- else :
41- _logger .warning (f"Service '{ plugin_name } .{ service_name } ' has no 'init' function" )
42-
43-
4425async def init (controller_enabled : bool , executor_enabled : bool ) -> None :
4526 """Initialize the application dependencies. Some of the components will behave differently if
4627 they start with or without the controller."""
@@ -53,35 +34,23 @@ async def init(controller_enabled: bool, executor_enabled: bool) -> None:
5334 await http_server .init (controller_enabled )
5435
5536 plugins .load_plugins ()
56- await init_plugins_services (controller_enabled , executor_enabled )
37+ await plugins . services . init_plugin_services (controller_enabled , executor_enabled )
5738
5839 # The following modules depend on the plugins being loaded
5940 await databases .init ()
6041 await message_queue .init ()
6142
6243
63- async def stop_plugins_services () -> None :
64- """Stop the plugins services"""
65- for plugin_name , plugin in plugins .loaded_plugins .items ():
66- _logger .info (f"Stopping plugin '{ plugin_name } '" )
67-
68- plugin_services = getattr (plugin , "services" , None )
69- if plugin_services is None :
70- continue
71-
72- for service_name in plugin_services .__all__ :
73- service = getattr (plugin_services , service_name )
74- if hasattr (service , "stop" ):
75- await protected_task (service .stop ())
76-
77-
78- async def finish () -> None :
44+ async def finish (controller_enabled : bool , executor_enabled : bool ) -> None :
7945 """Finish the application, making sure any exception won't impact other closing tasks"""
8046 await protected_task (_logger , http_server .wait_stop ())
8147 await protected_task (_logger , monitors_loader .wait_stop ())
8248 await protected_task (_logger , databases .close ())
8349 await protected_task (_logger , internal_database .close ())
84- await protected_task (_logger , plugins .services .stop ())
50+ await protected_task (
51+ _logger ,
52+ plugins .services .stop_plugin_services (controller_enabled , executor_enabled ),
53+ )
8554
8655
8756async def main () -> None :
@@ -103,7 +72,10 @@ async def main() -> None:
10372 tasks = [modes [mode ]() for mode in operation_modes ]
10473 await asyncio .gather (* tasks )
10574
106- await finish ()
75+ await finish (
76+ controller_enabled = "controller" in operation_modes ,
77+ executor_enabled = "executor" in operation_modes ,
78+ )
10779
10880
10981if __name__ == "__main__" :
0 commit comments