[REFORMAT] Ran black reformat

This commit is contained in:
c-d-p
2025-04-23 01:00:56 +02:00
parent d5d0a24403
commit 1553004efc
38 changed files with 1005 additions and 384 deletions

View File

@@ -1,14 +1,17 @@
# core/celery_app.py
from celery import Celery
from core.config import settings # Import your settings
from core.config import settings # Import your settings
celery_app = Celery(
"worker",
broker=settings.REDIS_URL,
backend=settings.REDIS_URL,
include=["modules.auth.tasks", "modules.admin.tasks"] # Add paths to modules containing tasks
include=[
"modules.auth.tasks",
"modules.admin.tasks",
], # Add paths to modules containing tasks
# Add other modules with tasks here, e.g., "modules.some_other_module.tasks"
)
# Optional: Update Celery configuration directly if needed
# celery_app.conf.update(task_track_started=True)
# celery_app.conf.update(task_track_started=True)

View File

@@ -4,12 +4,13 @@ import os
DOTENV_PATH = os.path.join(os.path.dirname(__file__), "../.env")
class Settings(BaseSettings):
# Database settings - reads DB_URL from environment or .env
DB_URL: str = "postgresql://maia:maia@localhost:5432/maia"
# Redis settings - reads REDIS_URL from environment or .env, also used for Celery.
REDIS_URL: str ="redis://localhost:6379/0"
REDIS_URL: str = "redis://localhost:6379/0"
# JWT settings - reads from environment or .env
JWT_ALGORITHM: str = "HS256"
@@ -19,13 +20,14 @@ class Settings(BaseSettings):
JWT_SECRET_KEY: str
# Other settings
GOOGLE_API_KEY: str = "" # Example with a default
GOOGLE_API_KEY: str = "" # Example with a default
class Config:
# Tell pydantic-settings to load variables from a .env file
env_file = DOTENV_PATH
env_file_encoding = 'utf-8'
extra = 'ignore'
env_file_encoding = "utf-8"
extra = "ignore"
# Create a single instance of the settings
settings = Settings()

View File

@@ -10,6 +10,7 @@ Base = declarative_base() # Used for models
_engine = None
_SessionLocal = None
def get_engine():
global _engine
if _engine is None:
@@ -20,10 +21,13 @@ def get_engine():
try:
_engine.connect()
except Exception:
raise Exception("Database connection failed. Is the database server running?")
raise Exception(
"Database connection failed. Is the database server running?"
)
Base.metadata.create_all(_engine) # Create tables here
return _engine
def get_sessionmaker():
global _SessionLocal
if _SessionLocal is None:
@@ -31,10 +35,11 @@ def get_sessionmaker():
_SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
return _SessionLocal
def get_db() -> Generator[Session, None, None]:
SessionLocal = get_sessionmaker()
db = SessionLocal()
try:
yield db
finally:
db.close()
db.close()

View File

@@ -8,20 +8,26 @@ from starlette.status import (
HTTP_409_CONFLICT,
)
def bad_request_exception(detail: str = "Bad Request"):
return HTTPException(status_code=HTTP_400_BAD_REQUEST, detail=detail)
def unauthorized_exception(detail: str = "Unauthorized"):
return HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail=detail)
def forbidden_exception(detail: str = "Forbidden"):
return HTTPException(status_code=HTTP_403_FORBIDDEN, detail=detail)
def not_found_exception(detail: str = "Not Found"):
return HTTPException(status_code=HTTP_404_NOT_FOUND, detail=detail)
def internal_server_error_exception(detail: str = "Internal Server Error"):
return HTTPException(status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail=detail)
def conflict_exception(detail: str = "Conflict"):
return HTTPException(status_code=HTTP_409_CONFLICT, detail=detail)
return HTTPException(status_code=HTTP_409_CONFLICT, detail=detail)