SPB Git

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

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

Simon-Pierre Boucher committed (Sep 4, 2026) parent ff8f31f Browse files

2 changed files +8 −3

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

Theme