This project is a multi-component application built with FastAPI. It combines a classic RESTful API for managing a to-do list with background processes powered by Celery and Redis, and integrates a machine learning model to predict task priority.
The project is composed of the following services, all running within Docker containers:
trainer
: Trains and saves the machine learning model. This service runs first.api
: The FastAPI application with core API endpoints and ML functionality.worker
: The Celery Worker for processing background tasks.beat
: The Celery Beat scheduler for running tasks on a schedule.redis
: The Celery task broker, also used for caching.tests
: A container for running automated unit tests.
Docker is a platform for developing, shipping, and running applications in containers.
- Go to the official Docker website.
- Download Docker Desktop for Windows.
- Run the installer and follow the instructions. Docker Desktop includes the Docker Engine, Docker CLI, and Docker Compose.
- After installation, launch Docker Desktop.
- Go to the official Docker website.
- Download Docker Desktop for Mac.
- Double-click the downloaded
.dmg
file and drag the Docker icon into your Applications folder. - Launch Docker Desktop from the Applications folder.
- Open your terminal.
- Update your package index:
sudo apt-get update
- Install Docker Engine, Docker CLI, and Containerd:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- Add your user to the
docker
group to run commands withoutsudo
:sudo usermod -aG docker $USER
- Log out and back in for the changes to take effect.
- Verify your Docker installation with:
docker run hello-world
-
Clone the repository. Open your terminal and use the following command to download the project:
git clone https://github.com/OldFox7322/technical-task-keymark
Then, navigate to the project's root directory:cd <your_project_directory>
-
Navigate to the project's root directory.
-
Start all services using Docker Compose. This will automatically build and launch all necessary containers and run the unit tests.
docker-compose up --build
-
Wait for all containers to start. The
trainer
service will run first to create the model, followed by theapi
, and then thetests
will run once theapi
is ready. The process is complete when you see a message about the tests successfully passing. -
Once running, your API will be available at:
- Base URL:
http://localhost:8000
- Interactive Docs (Swagger UI):
http://localhost:8000/docs
- Base URL:
The project provides the following API endpoints:
GET /tasks
: Retrieves a list of all tasks.POST /tasks
: Creates a new task.PUT /tasks/{id}
: Updates an existing task by its ID.DELETE /tasks/{id}
: Deletes a task by its ID.POST /predict
: Uses the machine learning model to predict a task's priority.POST /sync-users
: Launches a background task to synchronize user data from an external API.
Unit tests run automatically on startup. To run them manually, you can use:
docker-compose up --build --abort-on-container-exit tests