Skeleton ready

This commit is contained in:
2026-07-08 23:01:55 +04:00
commit d9e5effdce
75 changed files with 1989 additions and 0 deletions

View File

View 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()

View File

View File

@@ -0,0 +1,4 @@
from enum import Enum
class DateTime(str, Enum):
Ymd = "%Y-%m-%d"

View File

@@ -0,0 +1,4 @@
from enum import Enum
class Encoding(str, Enum):
utf8 = "utf-8"

View File

@@ -0,0 +1,5 @@
from punq import Container
class Kernel:
def get_container(self) -> Container:
raise NotImplementedError()

View File

View 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())

View File

@@ -0,0 +1,4 @@
from asyncio import Event
class StopEvent(Event):
pass

View File

View File

@@ -0,0 +1,7 @@
from dataclasses import dataclass
@dataclass(frozen=True)
class Application:
name: str
env: str

View 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

View 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 = "/"

View File

@@ -0,0 +1,8 @@
from dataclasses import dataclass
@dataclass(frozen=True)
class Redis:
host: str = "localhost"
port: int = 6379
db: int = 0