TaskFlow is a distributed task queue system designed to manage, schedule, and execute background jobs across multiple worker processes. It supports both Python and C++ workers, allowing for flexible and scalable task processing.
- API Service (
api/): Exposes endpoints for task submission, status checks, API key management, and authentication. - Worker Service (
worker/,worker_cpp/): Processes tasks from the queue. Python workers are implemented inworker/worker.py, and C++ workers are scaffolded inworker_cpp/worker.cpp. - Database (
core/database.py, models): Stores users, API keys, and task metadata. - Queue Manager (
core/queue_manager.py): Handles task queuing and dispatching. - Redis (
core/redis_client.py): Used for fast in-memory task queueing and rate limiting. - Janitor Script (
scripts/janitor.py): Cleans up expired or inactive API keys from the database.
- Task Submission: Submit tasks via REST API endpoints.
- API Key Management: Create, list, and delete API keys for secure access.
- Rate Limiting: Prevents abuse by limiting the number of requests per user.
- Worker Support: Python and C++ workers for flexible task execution.
- Soft and Hard Delete for API Keys: Inactive keys are first deactivated, then permanently deleted after a retention period.
- Database Migrations: Managed with Alembic.
TaskFlow/
├── alembic.ini
├── docker-compose.yml
├── notes.md
├── README.md
├── requirements.txt
├── alembic/
├── api/
│ ├── __init__.py
│ ├── dockerfile
│ ├── main.py
│ ├── oauth2.py
│ ├── rate_limiter.py
│ ├── schemas.py
│ ├── utils.py
│ └── routers/
│ ├── __init__.py
│ ├── api_keys.py
│ ├── auth.py
│ ├── status.py
│ ├── tasks.py
│ └── user.py
├── core/
│ ├── __init__.py
│ ├── config.py
│ ├── database.py
│ ├── models.py
│ ├── queue_manager.py
│ └── redis_client.py
├── scripts/
│ ├── __init__.py
│ └── janitor.py
├── worker/
│ ├── __init__.py
│ ├── dockerfile
│ └── worker.py
├── worker_cpp/
│ ├── dockerfile
│ └── worker.cpp
- Janitor Script: Run
python3 -m scripts.janitorto deactivate stale API keys and delete old inactive keys.
- Install dependencies:
pip install -r requirements.txt - Run database migrations:
alembic upgrade head - Start API service:
uvicorn api.main:app - Start worker(s):
python3 worker/worker.py - Build and run C++ worker:
Seeworker_cpp/worker.cppandworker_cpp/dockerfile.