CommentAutomation
Python project initialized with uv.
Quick start
-
Install uv.
-
Sync dependencies:
uv sync --group dev
-
Run the app:
uv run uvicorn comment_automation.main:app --app-dir src --host 0.0.0.0 --port 8000
-
Run tests:
uv run pytest
Webhooks
Instagram comments webhook endpoint:
- POST /webhooks/instagram/comments
The route validates incoming payloads and enqueues a Celery task.
LLM task configuration
The Celery task that handles webhook payload forwarding reads these environment variables:
- LLM_ENDPOINT_URL (required): Full HTTP(S) URL for the downstream LLM endpoint.
- LLM_ENDPOINT_API_KEY (optional): Bearer token sent as Authorization header.
- LLM_ENDPOINT_TIMEOUT_SECONDS (optional): Request timeout in seconds. Defaults to 10.
Retry behavior is built into the task:
- Retries transient failures (network/timeouts and HTTP 429/500/502/503/504).
- Exponential backoff enabled.
- Retry delay is jittered.
- Maximum retries is 7.
Running a Celery worker
The Celery entrypoint is in src/comment_automation/celery_app.py.
It reads these environment variables:
- CELERY_BROKER_URL (optional): Message broker URL. Defaults to redis://localhost:6379/0.
- CELERY_RESULT_BACKEND (optional): Result backend URL. Defaults to redis://localhost:6379/0.
With uv:
uv run celery -A comment_automation.celery_app:celery_app worker --loglevel=info
Without uv (venv already created):
./.venv/bin/celery -A comment_automation.celery_app:celery_app worker --loglevel=info
Docker targets and entrypoint modes
The container uses entrypoint.sh and supports two main modes:
- http: starts the FastAPI app.
- celery: starts the Celery worker.
Build local/test target (installs all dependency groups):
docker build --target local_test -t comment-automation:local .
Build production target (installs only non-dev dependencies):
docker build --target production -t comment-automation:prod .
Run HTTP app (default mode):
docker run --rm -p 8000:8000 comment-automation:prod
Run Celery worker mode:
docker run --rm
-e CELERY_BROKER_URL=redis://host.docker.internal:6379/0
-e CELERY_RESULT_BACKEND=redis://host.docker.internal:6379/0
comment-automation:prod celery