Skip to content

Commit e38d8ca

Browse files
committed
feat: add yaml config
1 parent eb833ab commit e38d8ca

File tree

13 files changed

+117
-23
lines changed

13 files changed

+117
-23
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ cython_debug/
175175
.ruff_cache
176176
.uv_cache
177177

178-
tg_secrets.toml
178+
deploy/dev/tgdb/clients/*
179+
!deploy/dev/tgdb/clients/.gitkeep
179180
*.session
181+
180182
x.py
183+
y.py
184+
z.py
181185

deploy/dev/docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
volumes:
1313
- ../..:/app
1414
- tgdb-data:/run/app
15+
environments:
16+
CONF_PATH: /app/deploy/dev/tgdb/conf.yaml
1517
command: bash
1618

1719
volumes:

deploy/dev/tgdb/clients/.gitkeep

Whitespace-only changes.

deploy/dev/tgdb/conf.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
conf:
2+
api:
3+
id: 23598539
4+
hash: "6d9d7305ffc6f148dab120d24541b127"
5+
6+
clients:
7+
bots: "/app/deploy/dev/tgdb/bots/bots.txt"
8+
userbots: "/app/deploy/dev/tgdb/bots/userbots.txt"
9+
10+
heap:
11+
chat: -1005010263669
12+
page:
13+
fullness: 0.8
14+
15+
relations:
16+
chat: -1005000098156
17+
vacuum:
18+
window_delay_seconds: 30
19+
min_message_count: 1
20+
21+
buffer:
22+
chat: -1005014396610
23+
overflow:
24+
len: 5000
25+
timeout_seconds: 0.1
26+
27+
vacuum:
28+
window_delay_seconds: 10
29+
min_message_count: 200

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ license = { file = "LICENSE" }
1010
requires-python = ">=3.13"
1111
dependencies = [
1212
"telethon>=1.40.0",
13-
"websockets>=15.0",
1413
"in-memory-db>=0.3.0",
1514
"typenv>=0.2.0",
1615
"dishka>=1.4.2",
1716
"fastapi>=0.115.2",
1817
"pydantic>=2.11.4",
1918
"uvicorn[standard]>=0.30.6",
19+
"pyyaml>=6.0.2",
2020
]
2121

2222
[project.urls]

src/tgdb/infrastructure/pyyaml/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from dataclasses import dataclass
2+
from pathlib import Path
3+
4+
import yaml
5+
6+
7+
@dataclass(frozen=True)
8+
class Conf:
9+
api_id: int
10+
api_hash: str
11+
12+
clients_bots: str
13+
clients_userbots: str
14+
15+
heap_chat: int
16+
heap_page_fullness: float
17+
18+
relations_chat: int
19+
relations_vacuum_window_delay_seconds: int
20+
relations_vacuum_min_message_count: int
21+
22+
buffer_chat: int
23+
buffer_overflow_len: int
24+
buffer_overflow_timeout_seconds: float
25+
buffer_vacuum_window_delay_seconds: int
26+
buffer_vacuum_min_message_count: int
27+
28+
@classmethod
29+
def load(cls, path: Path) -> "Conf":
30+
with path.open("r") as file:
31+
data = yaml.safe_load(file)
32+
33+
conf = data["conf"]
34+
35+
return cls(
36+
api_id=conf["api"]["id"],
37+
api_hash=conf["api"]["hash"],
38+
39+
clients_bots=conf["clients"]["bots"],
40+
clients_userbots=conf["clients"]["userbots"],
41+
42+
heap_chat=conf["heap"]["chat"],
43+
heap_page_fullness=conf["heap"]["page"]["fullness"],
44+
45+
relations_chat=conf["relations"]["chat"],
46+
relations_vacuum_window_delay_seconds=conf["relations"]["vacuum"]["window_delay_seconds"],
47+
relations_vacuum_min_message_count=conf["relations"]["vacuum"]["min_message_count"],
48+
49+
buffer_chat=conf["buffer"]["chat"],
50+
buffer_overflow_len=conf["buffer"]["overflow"]["len"],
51+
buffer_overflow_timeout_seconds=conf["buffer"]["overflow"]["timeout_seconds"],
52+
buffer_vacuum_window_delay_seconds=conf["buffer"]["vacuum"]["window_delay_seconds"],
53+
buffer_vacuum_min_message_count=conf["buffer"]["vacuum"]["min_message_count"],
54+
)

src/tgdb/infrastructure/telegram_secrets.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/tgdb/infrastructure/typenv/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from dataclasses import dataclass
2+
from pathlib import Path
3+
4+
import typenv
5+
6+
7+
@dataclass(frozen=True)
8+
class Envs:
9+
conf_path: Path
10+
11+
@classmethod
12+
def load(cls) -> "Envs":
13+
env = typenv.Env()
14+
15+
return Envs(
16+
conf_path=Path(env.str("CONF_PATH")),
17+
)

0 commit comments

Comments
 (0)