Added logic to handle async applicationBase
This commit is contained in:
@@ -34,6 +34,28 @@ class ApplicationABC(ABC):
|
||||
self.main()
|
||||
except KeyboardInterrupt:
|
||||
Console.close()
|
||||
|
||||
def run(self):
|
||||
r"""Entry point
|
||||
|
||||
Called by custom Application.main
|
||||
"""
|
||||
try:
|
||||
self.configure()
|
||||
self.main()
|
||||
except KeyboardInterrupt:
|
||||
Console.close()
|
||||
|
||||
async def run_async(self):
|
||||
r"""Entry point
|
||||
|
||||
Called by custom Application.main
|
||||
"""
|
||||
try:
|
||||
await self.configure()
|
||||
await self.main()
|
||||
except KeyboardInterrupt:
|
||||
Console.close()
|
||||
|
||||
@abstractmethod
|
||||
def configure(self):
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import types
|
||||
from typing import Type, Optional, Callable
|
||||
|
||||
from cpl_core.application.application_abc import ApplicationABC
|
||||
@@ -6,7 +5,6 @@ from cpl_core.application.application_builder_abc import ApplicationBuilderABC
|
||||
from cpl_core.application.application_extension_abc import ApplicationExtensionABC
|
||||
from cpl_core.application.startup_abc import StartupABC
|
||||
from cpl_core.configuration.configuration import Configuration
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection.service_collection import ServiceCollection
|
||||
|
||||
|
||||
@@ -50,3 +48,17 @@ class ApplicationBuilder(ApplicationBuilderABC):
|
||||
extension.run(config, services)
|
||||
|
||||
return self._app(config, services)
|
||||
|
||||
async def build_async(self) -> ApplicationABC:
|
||||
if self._startup is not None:
|
||||
await self._startup.configure_configuration(self._configuration, self._environment)
|
||||
await self._startup.configure_services(self._services, self._environment)
|
||||
|
||||
config = self._configuration
|
||||
services = self._services.build_service_provider()
|
||||
|
||||
for ex in self._extensions:
|
||||
extension = ex()
|
||||
await extension.run(config, services)
|
||||
|
||||
return self._app(config, services)
|
||||
|
@@ -23,6 +23,17 @@ class ApplicationBuilderABC(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def use_startup(self, startup: Type[StartupABC]):
|
||||
r"""Sets the custom startup class to use async
|
||||
|
||||
Parameter
|
||||
---------
|
||||
startup: Type[:class:`cpl_core.application.startup_abc.StartupABC`]
|
||||
Startup class to use
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def build(self) -> ApplicationABC:
|
||||
r"""Creates custom application object
|
||||
@@ -32,3 +43,13 @@ class ApplicationBuilderABC(ABC):
|
||||
Object of :class:`cpl_core.application.application_abc.ApplicationABC`
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def build_async(self) -> ApplicationABC:
|
||||
r"""Creates custom application object async
|
||||
|
||||
Returns
|
||||
-------
|
||||
Object of :class:`cpl_core.application.application_abc.ApplicationABC`
|
||||
"""
|
||||
pass
|
||||
|
@@ -11,3 +11,6 @@ class ApplicationExtensionABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def run(self, config: ConfigurationABC, services: ServiceProviderABC): pass
|
||||
|
||||
@abstractmethod
|
||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC): pass
|
||||
|
Reference in New Issue
Block a user