SPB Git forge

spb/api-ka

Public

API-KA — plateforme centrale : collecte quotidienne des 8 services KA, historisation append-only et API publique sur www.api-ka.com

48commits 1branches 0releases
5.9 MBsize
maindefault branch
19 days agolast push
Python 60.9% HTML 21% TypeScript 7.3% JavaScript 5.2% CSS 4.8% Shell 0.8%

config: nœud imposé optionnel (APIKA_REQUIRED_NODE) — placement par maclustr-dispatch

Simon-Pierre Boucher committed 20 days ago (Sep 4, 2026) parent ff8f31f

2 changed files +8 −3

modified src/config.py +3 −2
@@ -18,7 +18,8 @@ from pathlib import Path
18 18
19 19 from dotenv import load_dotenv
20 20
21 −REQUIRED_NODE = "m3u96b"
21 +# Nœud imposé (optionnel) : APIKA_REQUIRED_NODE=m3u96b ; vide = tourne sur n'importe quel nœud (placement par maclustr-dispatch).
22 +REQUIRED_NODE = os.getenv("APIKA_REQUIRED_NODE", "").strip().lower()
22 23
23 24 SERVICES: tuple[str, ...] = (
24 25 "louka",
@@ -63,7 +64,7 @@ def verify_node() -> None:
63 64 API-KA ne tourne que sur le node m3u96b.
64 65 """
65 66 hostname = socket.gethostname()
66 − if os.getenv("APP_ENV") == "production":
67 + if os.getenv("APP_ENV") == "production" and REQUIRED_NODE:
67 68 short = hostname.split(".")[0].lower()
68 69 if short != REQUIRED_NODE:
69 70 raise RuntimeError(
modified src/database/models.py +5 −1
@@ -32,8 +32,12 @@ from sqlalchemy.dialects.postgresql import JSONB
32 32 from sqlalchemy.orm import DeclarativeBase, Mapped, declared_attr, mapped_column
33 33 from sqlalchemy.types import JSON
34 34
35 +import socket
36 +
35 37 from src.config import REQUIRED_NODE
36 38
39 +CURRENT_NODE = REQUIRED_NODE or socket.gethostname().split(".")[0].lower()
40 +
37 41 # BIGSERIAL sur PostgreSQL ; INTEGER auto-incrémenté en dev SQLite.
38 42 BigIntPK = BigInteger().with_variant(Integer(), "sqlite")
39 43 # JSONB sur PostgreSQL ; JSON générique en dev SQLite.
@@ -170,7 +174,7 @@ class CollectionRun(Base):
170 174 records_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
171 175 duration_seconds: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
172 176 error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
173 − node: Mapped[str] = mapped_column(Text, nullable=False, default=REQUIRED_NODE)
177 + node: Mapped[str] = mapped_column(Text, nullable=False, default=CURRENT_NODE)
174 178 started_at: Mapped[datetime.datetime] = mapped_column(
175 179 DateTime(timezone=True), nullable=False
176 180 )
177 181