refactor: implement packet parsing heuristics and introduce device-level state caching to throttle database writes and vitals updates
This commit is contained in:
@@ -8,6 +8,7 @@ class Settings(BaseSettings):
|
||||
contec_ports: list = [511, 515, 516, 517, 518, 519, 520]
|
||||
monitor_ip: str = ""
|
||||
monitor_model: str = "CMS7000PLUS"
|
||||
device_models: dict = {}
|
||||
target_api_url: str = "https://api.example.com/vitals"
|
||||
api_token: str = ""
|
||||
retry_interval_seconds: int = 60
|
||||
@@ -18,14 +19,27 @@ class Settings(BaseSettings):
|
||||
env_file = ".env"
|
||||
|
||||
def get_settings() -> Settings:
|
||||
config_file = "config.json"
|
||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
config_file = os.path.join(base_dir, "config.json")
|
||||
|
||||
settings_obj = Settings()
|
||||
|
||||
if os.path.exists(config_file):
|
||||
with open(config_file, "r") as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
return Settings(**data)
|
||||
for k, v in data.items():
|
||||
setattr(settings_obj, k, v)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
return Settings()
|
||||
|
||||
if settings_obj.database_url.startswith("sqlite:///./"):
|
||||
db_name = settings_obj.database_url.split("sqlite:///./")[1]
|
||||
settings_obj.database_url = f"sqlite:///{os.path.join(base_dir, db_name)}"
|
||||
|
||||
if not os.path.isabs(settings_obj.log_file):
|
||||
settings_obj.log_file = os.path.join(base_dir, settings_obj.log_file)
|
||||
|
||||
return settings_obj
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
Reference in New Issue
Block a user