This is the worker backend API for the WebBuddhist application.
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
This worker backend shares the same databases as app-pecha-backend. Ensure the databases are running:
- Navigate to the app-pecha-backend local setup directory:
cd ../app-pecha-backend/local_setup - Start the databases using Docker (if not already running):
docker-compose up -d
- Return to webuddhist-worker directory:
cd ../../webuddhist-worker - Apply database migrations:
poetry run alembic upgrade head
- Start the FastAPI development server:
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 html Open the coverage report:
open htmlcov/index.html Alembic is used for handling database migrations. Here are some common commands:
-
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 backend shares the following infrastructure with app-pecha-backend:
- PostgreSQL database (port 5434)
- MongoDB database (port 27017)
- Redis/Dragonfly cache (port 6379)
- Elasticsearch (port 9200)
Both backends can run simultaneously:
app-pecha-backend: http://127.0.0.1:8000webuddhist-worker: http://127.0.0.1:8001
When transferring endpoints from app-pecha-backend:
- Copy the relevant models, services, repositories, and views
- Update imports to use
worker_apiinstead ofpecha_api - Add model imports to
migrations/env.pyfor Alembic - Add document models to
worker_api/db/mongo_database.pyfor Beanie - Include routers in
worker_api/app.py - Run migrations if needed
- Update tests accordingly