Skeleton ready
This commit is contained in:
0
kernel/application/__init__.py
Normal file
0
kernel/application/__init__.py
Normal file
39
kernel/application/application.py
Normal file
39
kernel/application/application.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from typing import List, Callable, Concatenate, Awaitable
|
||||
from abc import ABC, abstractmethod
|
||||
from punq import Container
|
||||
|
||||
from kernel.feature.provider import Provider
|
||||
from kernel.application.kernel import Kernel
|
||||
|
||||
class Application(ABC):
|
||||
__kernel: Kernel
|
||||
__features: List[Provider]
|
||||
|
||||
@abstractmethod
|
||||
async def do(
|
||||
self,
|
||||
callback: Callable[Concatenate[Container, ...], Awaitable[None]]
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
def __init__(self, kernel: Kernel, features: List[type[Provider]]) -> None:
|
||||
self.__kernel = kernel
|
||||
self.__features = []
|
||||
|
||||
for feature in features:
|
||||
feature_instance = feature(kernel.get_container())
|
||||
feature_instance.register()
|
||||
|
||||
self.__features.append(feature_instance)
|
||||
|
||||
async def launch(
|
||||
self,
|
||||
callback: Callable[Concatenate[Container, ...], Awaitable[None]]
|
||||
) -> None:
|
||||
for feature in self.__features:
|
||||
feature.bootstrap()
|
||||
|
||||
await self.do(callback)
|
||||
|
||||
def get_container(self) -> Container:
|
||||
return self.__kernel.get_container()
|
||||
0
kernel/application/enum/__init__.py
Normal file
0
kernel/application/enum/__init__.py
Normal file
4
kernel/application/enum/date_time.py
Normal file
4
kernel/application/enum/date_time.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from enum import Enum
|
||||
|
||||
class DateTime(str, Enum):
|
||||
Ymd = "%Y-%m-%d"
|
||||
4
kernel/application/enum/encoding.py
Normal file
4
kernel/application/enum/encoding.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from enum import Enum
|
||||
|
||||
class Encoding(str, Enum):
|
||||
utf8 = "utf-8"
|
||||
5
kernel/application/kernel.py
Normal file
5
kernel/application/kernel.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from punq import Container
|
||||
|
||||
class Kernel:
|
||||
def get_container(self) -> Container:
|
||||
raise NotImplementedError()
|
||||
0
kernel/application/manager/__init__.py
Normal file
0
kernel/application/manager/__init__.py
Normal file
13
kernel/application/manager/stop_event.py
Normal file
13
kernel/application/manager/stop_event.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from asyncio import Event
|
||||
from signal import signal, SIGINT, SIGTERM
|
||||
|
||||
class StopEvent:
|
||||
__event: Event
|
||||
|
||||
def __init__(self, event: Event) -> None:
|
||||
self.__event = event
|
||||
|
||||
def setup_stop_signals(self) -> None:
|
||||
for signum in (SIGINT, SIGTERM):
|
||||
signal(signum, lambda sig, frame: self.__event.set())
|
||||
|
||||
4
kernel/application/stop_event.py
Normal file
4
kernel/application/stop_event.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from asyncio import Event
|
||||
|
||||
class StopEvent(Event):
|
||||
pass
|
||||
0
kernel/application/view/__init__.py
Normal file
0
kernel/application/view/__init__.py
Normal file
7
kernel/application/view/application.py
Normal file
7
kernel/application/view/application.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Application:
|
||||
name: str
|
||||
env: str
|
||||
28
kernel/application/view/configuration.py
Normal file
28
kernel/application/view/configuration.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from kernel.application.view.application import Application
|
||||
from kernel.application.view.rabbitmq import RabbitMQ
|
||||
from kernel.application.view.redis import Redis
|
||||
|
||||
|
||||
class Configuration():
|
||||
__application: Application
|
||||
__rabbitmq: RabbitMQ
|
||||
__redis: Redis
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
application: Application,
|
||||
rabbitmq: RabbitMQ,
|
||||
redis: Redis,
|
||||
) -> None:
|
||||
self.__application = application
|
||||
self.__rabbitmq = rabbitmq
|
||||
self.__redis = redis
|
||||
|
||||
def application(self) -> Application:
|
||||
return self.__application
|
||||
|
||||
def rabbitmq(self) -> RabbitMQ:
|
||||
return self.__rabbitmq
|
||||
|
||||
def redis(self) -> Redis:
|
||||
return self.__redis
|
||||
11
kernel/application/view/rabbitmq.py
Normal file
11
kernel/application/view/rabbitmq.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RabbitMQ:
|
||||
host: str = "localhost"
|
||||
port: int = 5672
|
||||
user: str = "guest"
|
||||
password: str = "guest"
|
||||
timeout: int = 10
|
||||
vhost: str = "/"
|
||||
8
kernel/application/view/redis.py
Normal file
8
kernel/application/view/redis.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Redis:
|
||||
host: str = "localhost"
|
||||
port: int = 6379
|
||||
db: int = 0
|
||||
Reference in New Issue
Block a user