Harden database startup for Portainer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from functools import lru_cache
|
||||
|
||||
from sqlalchemy.engine import URL
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -7,13 +8,33 @@ class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||
|
||||
app_name: str = "Plast Track MVP"
|
||||
database_url: str = "postgresql+psycopg://plasttrack:plasttrack@database:5432/plasttrack"
|
||||
database_url: str | None = None
|
||||
postgres_host: str = "database"
|
||||
postgres_port: int = 5432
|
||||
postgres_db: str = "plasttrack"
|
||||
postgres_user: str = "plasttrack"
|
||||
postgres_password: str = "plasttrack"
|
||||
mqtt_host: str = "mqtt"
|
||||
mqtt_port: int = 1883
|
||||
mqtt_topic: str = "plasttrack/machines/+/events"
|
||||
mqtt_client_id: str = "plast-track-backend"
|
||||
frontend_origin: str = "http://localhost:5173"
|
||||
downtime_check_interval_sec: int = 5
|
||||
database_startup_retries: int = 30
|
||||
database_startup_retry_delay_sec: float = 2.0
|
||||
|
||||
@property
|
||||
def sqlalchemy_database_url(self) -> str:
|
||||
if self.database_url:
|
||||
return self.database_url
|
||||
return URL.create(
|
||||
"postgresql+psycopg",
|
||||
username=self.postgres_user,
|
||||
password=self.postgres_password,
|
||||
host=self.postgres_host,
|
||||
port=self.postgres_port,
|
||||
database=self.postgres_db,
|
||||
).render_as_string(hide_password=False)
|
||||
|
||||
|
||||
@lru_cache
|
||||
|
||||
Reference in New Issue
Block a user