Skip to content

Commit 403b571

Browse files
committed
main initializes services from plugins
1 parent aeb6342 commit 403b571

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import databases as databases
1212
import internal_database as internal_database
1313
import message_queue as message_queue
14+
import plugins as plugins
1415
import registry as registry
1516
import utils.app as app
1617
import utils.log as log
@@ -25,6 +26,21 @@ async def protected_task(task):
2526
_logger.warning(f"Exception with task '{task}'")
2627

2728

29+
async def init_plugins_services(controller_enabled: bool, executor_enabled: bool):
30+
"""Initialize the plugins services"""
31+
for plugin_name, plugin in plugins.loaded_plugins.items():
32+
_logger.info(f"Loading plugin {plugin_name}")
33+
34+
plugin_services = getattr(plugin, "services", None)
35+
if plugin_services is None:
36+
continue
37+
38+
for service_name in plugin_services.__all__:
39+
service = getattr(plugin_services, service_name)
40+
if hasattr(service, "init"):
41+
await service.init(controller_enabled, executor_enabled)
42+
43+
2844
async def init(controller_enabled: bool, executor_enabled: bool):
2945
"""Initialize the application dependencies. Some of the components will behave differently if
3046
they start with or without the controller."""
@@ -38,13 +54,31 @@ async def init(controller_enabled: bool, executor_enabled: bool):
3854
await message_queue.init()
3955
await http_server.init(controller_enabled)
4056

57+
await init_plugins_services(controller_enabled, executor_enabled)
58+
59+
60+
async def stop_plugins_services():
61+
"""Stop the plugins services"""
62+
for plugin_name, plugin in plugins.loaded_plugins.items():
63+
_logger.info(f"Loading plugin {plugin_name}")
64+
65+
plugin_services = getattr(plugin, "services", None)
66+
if plugin_services is None:
67+
continue
68+
69+
for service_name in plugin_services.__all__:
70+
service = getattr(plugin_services, service_name)
71+
if hasattr(service, "stop"):
72+
await protected_task(service.stop())
73+
4174

4275
async def finish():
4376
"""Finish the application, making sure any exception won't impact other closing tasks"""
4477
await protected_task(http_server.wait_stop())
4578
await protected_task(monitors_loader.wait_stop())
4679
await protected_task(databases.close())
4780
await protected_task(internal_database.close())
81+
await protected_task(stop_plugins_services())
4882

4983

5084
async def main():

0 commit comments

Comments
 (0)