mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
__all__ = ["Orchestrator"]
|
|
|
|
from dishka import Provider, make_container
|
|
|
|
from argenta.app import App
|
|
from argenta.di.integration import setup_dishka
|
|
from argenta.di.providers import SystemProvider
|
|
from argenta.orchestrator.argparser import ArgParser
|
|
|
|
DEFAULT_ARGPARSER: ArgParser = ArgParser(processed_args=[])
|
|
|
|
|
|
class Orchestrator:
|
|
def __init__(
|
|
self,
|
|
arg_parser: ArgParser | None = None,
|
|
custom_providers: list[Provider] | None = None,
|
|
auto_inject_handlers: bool = True,
|
|
):
|
|
"""
|
|
Public. An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
|
:param arg_parser: Cmd argument parser and configurator at startup
|
|
:return: None
|
|
"""
|
|
self._arg_parser: ArgParser | None = arg_parser
|
|
self._custom_providers: list[Provider] = custom_providers or []
|
|
self._auto_inject_handlers: bool = auto_inject_handlers
|
|
|
|
if self._arg_parser is not None:
|
|
self._arg_parser._parse_args()
|
|
|
|
def start_polling(self, app: App) -> None:
|
|
"""
|
|
Public. Starting the user input processing cycle
|
|
:param app: a running application
|
|
:return: None
|
|
"""
|
|
container = make_container(
|
|
SystemProvider(), *self._custom_providers, context={ArgParser: self._arg_parser}
|
|
)
|
|
setup_dishka(app, container, auto_inject=self._auto_inject_handlers)
|
|
|
|
app._run_polling()
|