This is the worker backend API for the WebBuddhist application.
It handles background work such as TTS/audio generation and notification dispatch. Plan/content data owned by the main backend is accessed only via HTTP APIs — the worker does not share or query the backend Postgres schema for subtasks, plan days, or related domain tables.
Follow these steps to set up the project on your local machine:
- Clone the repository:
git clone https://github.com/yourusername/webuddhist-worker.git
- Navigate to the project directory:
cd webuddhist-worker - Install the dependencies:
poetry install
Set at least:
| Variable | Purpose |
|---|---|
BACKEND_API_URL |
Base URL of the main backend API (default http://127.0.0.1:8000/api/v1) |
NOTIFICATION_DISPATCH_SECRET_TOKEN |
Shared secret sent as X-Dispatch-Token on internal backend calls |
DATABASE_URL |
Worker-owned Postgres (reminders / notification tables only) |
AUDIO_SQS_QUEUE_URL |
SQS queue for audio jobs produced by the backend |
CHAT_NOTIFICATION_SQS_QUEUE_URL |
SQS queue for chat message notification events produced by the backend |
PRAYER_NOTIFICATION_SQS_QUEUE_URL |
SQS queue for prayer (PRAYER_RECEIVED) notification events produced by the backend |
CACHE_CONNECTION_STRING |
Redis URL used for chat notification per-device idempotency |
The worker talks to the backend for audio job status, generation payloads
(day/subtask content), and persisting generation results. Do not point
DATABASE_URL at the backend database for plan/subtask data.
Start local infra from the backend repo if needed (Postgres/Mongo/Redis/etc.), then apply worker migrations against the worker database:
poetry run alembic upgrade headThese migrations cover worker tables (e.g. upcoming reminders), not backend plan tables.
- Ensure the main backend is running (default
http://127.0.0.1:8000). - Start the worker:
poetry run uvicorn worker_api.app:api --port 8001 --reload
The application will be available at http://127.0.0.1:8001/.
You can access the Swagger UI for the API documentation at http://127.0.0.1:8001/docs.
To run tests, execute the following command:
poetry run pytestTo check the coverage:
poetry run pytest --cov=worker_apipoetry run coverage htmlOpen the coverage report:
open htmlcov/index.htmlAlembic is used for handling worker-owned database migrations:
-
Create a new migration:
poetry run alembic revision --autogenerate -m "description of migration" -
Apply the latest migrations:
poetry run alembic upgrade head
-
Downgrade to a previous migration:
poetry run alembic downgrade -1
-
View the current migration history:
poetry run alembic history -
Show the current migration state:
poetry run alembic current
This worker can reuse the same local Docker services as WeBuddhist-Backend
(Postgres, MongoDB, Redis, Elasticsearch), but:
- Backend plan/content data is fetched and updated through backend internal APIs
- Worker Postgres should only hold worker-owned tables
Typical local ports:
- PostgreSQL: 5434
- MongoDB: 27017
- Redis/Dragonfly: 6379
- Elasticsearch: 9200
Both apps can run simultaneously:
WeBuddhist-Backend: http://127.0.0.1:8000webuddhist-worker: http://127.0.0.1:8001