first commit
This commit is contained in:
parent
8e58e24d2e
commit
973c47ff25
16 changed files with 866 additions and 0 deletions
38
config.py
Normal file
38
config.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import yaml
|
||||
from pydantic_settings import BaseSettings
|
||||
from logger import logger
|
||||
|
||||
# Configuration path
|
||||
config_path = "config/config.yaml"
|
||||
|
||||
class Settings(BaseSettings):
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
class Config:
|
||||
def __init__(self, path: str = config_path):
|
||||
self.path = path
|
||||
self.config = None
|
||||
|
||||
|
||||
def load_config(self):
|
||||
try:
|
||||
with open(self.path, 'r') as file:
|
||||
logger.info({"config_load": f"load_config:{self.path}"})
|
||||
data = yaml.safe_load(file)
|
||||
logger.info({"config_load": f"config load successfully"})
|
||||
self.config = Settings(**data)
|
||||
#logger.info({"config_update": f"Config updated with: {data}"})
|
||||
except FileNotFoundError as e:
|
||||
logger.error({"config_err": f"File not found: {e}"})
|
||||
raise Exception(f"File not found: {e}")
|
||||
except yaml.YAMLError as e:
|
||||
logger.error({"config_err": f"YAML error: {e}"})
|
||||
raise Exception(f"YAML error: {e}")
|
||||
except Exception as e:
|
||||
logger.error({"config_err": f"Unexpected error: {e}"})
|
||||
raise Exception(f"Failed to load config: {e}")
|
||||
|
||||
def reload_config(self) -> None:
|
||||
self.load_config()
|
Loading…
Add table
Add a link
Reference in a new issue