Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ FIRST_SUPERUSER=admin@example.com
FIRST_SUPERUSER_PASSWORD=changethis
USERS_OPEN_REGISTRATION=True

# Celery
CELERY_BROKER_URL="redis://127.0.0.1:6379/0"
CELERY_RESULT_BACKEND="redis://127.0.0.1:6379"

# Postgres
POSTGRES_SERVER=localhost
Expand Down
38 changes: 38 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
services:
web:
image: 4ndresor/flashcards_api
container_name: fastapi_app
command: uvicorn src.main:app --host 0.0.0.0 --port 8000
env_file:
- .env
ports:
- "8000:8000"
depends_on:
- postgres
- redis

redis:
image: redis:7-alpine
container_name: redis
ports:
- "6379:6379"

celery:
image: 4ndresor/flashcards_api
container_name: celery_worker
command: celery -A celery_worker.celery worker --loglevel=info
env_file:
- .env
depends_on:
- redis

celery-flower:
image: mher/flower
container_name: celery-flower
ports:
- "5555:5555"
command: celery --broker=redis://redis:6379/0 flower --port=5555
env_file:
- .env
depends_on:
- redis
2 changes: 2 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependencies = [
"fastapi-pagination>=0.12.34",
"bcrypt==4.0.1",
"google-genai>=1.5.0",
"celery[redis]>=5.5.2",
"flower>=2.0.1",
]

[tool.uv]
Expand Down
3 changes: 3 additions & 0 deletions backend/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Settings(BaseSettings):
POSTGRES_PASSWORD: str
POSTGRES_DB: str = ""

CELERY_BROKER_URL: str
CELERY_RESULT_BACKEND: str

@computed_field # type: ignore[misc]
@property
def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
Expand Down
Empty file added backend/src/tasks.py
Empty file.
13 changes: 13 additions & 0 deletions backend/src/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from celery import Celery

from src.core.config import settings

celery = Celery(
"worker",
broker=settings.CELERY_BROKER_URL,
backend=settings.CELERY_RESULT_BACKEND,
)

celery.conf.task_routes = {
"src.tasks.*": {"queue": "default"},
}
1,713 changes: 972 additions & 741 deletions backend/uv.lock

Large diffs are not rendered by default.