Distributed task queue with capability matching. Workers announce what they can do and the scheduler matches jobs like a dating app.
Language: Python
Constraint: Automate the annoying thing
Stack: FastAPI, redis, websockets, pydantic
- Workers advertise capabilities (GPU, ARM, OS, toolchain)
- Scheduler matches jobs to workers via capability graph
- Redis-backed queue with priority support
- WebSocket progress streaming
- FastAPI control plane with OpenAPI docs
- Job retry with exponential backoff
- Dead letter queue for failed jobs
- Phase 1: FastAPI scaffold + Pydantic models (Job, Worker, Capability)
- Phase 2: Redis queue backend (lists + sorted sets)
- Phase 3: Worker registration and heartbeat protocol
- Phase 4: Capability matching engine (graph-based scoring)
- Phase 5: Job dispatch and execution lifecycle
- Phase 6: WebSocket progress streaming
- Phase 7: Retry logic and dead letter queue
- Phase 8: Control plane UI (FastAPI static)
- Phase 9: Docker compose for full stack
- Models:
Capability(with operator-based matching: eq, neq, gt, gte, lt, lte),Worker(status, heartbeat, capabilities),Job(priority, payload, required capabilities) - API Endpoints:
POST /jobs,GET /jobs,GET /jobs/{id},POST /workers,GET /workers,GET /workers/{id},POST /workers/{id}/heartbeat,GET /workers/{id}/health,GET /health/workers,POST /health/check,GET /match/{job_id} - Tests: 41 tests covering model validation, capability matching logic, and all API endpoints
- Redis Backend:
gridlock/redis_backend.pywith full CRUD for jobs and workers - Queue Operations: Sorted sets for priority queues, lists for FIFO queue, sets for status indexing
- Tests: 26 new Redis backend tests + updated integration tests = 67 total tests
- Run:
uvicorn gridlock.main:app --reload(requires Redis atREDIS_URL)
- Heartbeat Health Checks: Background task monitors worker heartbeats and automatically marks stale workers as
offline - Health Endpoints:
GET /workers/{id}/health(per-worker health),GET /health/workers(all workers summary),POST /health/check(manual stale worker check) - Configuration:
GRIDLOCK_HEARTBEAT_TIMEOUT(default 30s, time before worker considered stale),GRIDLOCK_HEARTBEAT_INTERVAL(default 10s, monitor check frequency) - Redis Backend: Added
get_stale_workers(),mark_worker_offline(),check_and_mark_stale_workers()for health management - Tests: 17 new health check tests covering stale detection, offline marking, and API endpoints
- Run: Same command, monitor starts automatically with the app
- Capability Matching Engine: Graph-based scoring with
matcher.pyfor job-to-worker compatibility - Match Scoring: Per-capability scoring with capacity bonuses (exceeding requirements gives higher scores)
- Ranked Matches:
GET /match/{job_id}/rankedreturns workers sorted by match quality - Compatibility Graph:
GET /graph/compatibilityreturns full bipartite graph for visualization - Tests: 29 matcher tests covering scoring algorithms, capacity bonuses, and graph construction
- Job Dispatch:
POST /jobs/{job_id}/dispatchassigns a pending job to an available worker (auto-match or specify worker_id) - Auto-Dispatch:
POST /dispatch/autoautomatically dispatches the highest priority job to the best matching worker - Job Completion:
POST /jobs/{job_id}/completemarks a running job as completed with optional result payload - Job Failure:
POST /jobs/{job_id}/failmarks a running job as failed with error message - Job Cancellation:
POST /jobs/{job_id}/cancelcancels a pending or running job - Worker Release: Completing, failing, or cancelling a running job automatically releases the worker back to available status
- Redis Backend: Added
dispatch_job(),complete_job(),fail_job(),cancel_job(),auto_dispatch(),get_next_dispatchable_job() - Tests: 50 new dispatch and lifecycle tests covering success paths, error conditions, and full lifecycles
- Total Tests: 193 tests passing
- Progress Updates:
POST /jobs/{job_id}/progressupdates a job's progress percentage (0-100) with optional status message and metadata - WebSocket Streaming:
WS /ws/jobs/{job_id}/progressstreams real-time progress updates to connected clients - In-Memory Broadcasting: WebSocket connections are managed in-memory for reliable real-time delivery; Redis pub/sub also available for cross-server setups
- Ping/Pong: WebSocket connections support
pingmessages for keepalive - Tests: 6 new progress streaming tests covering REST updates, WebSocket streaming, invalid ranges, and not-found handling
- Total Tests: 199 tests passing
- Retry Fields:
Jobmodel now includesretry_count,max_retries,retry_delay_seconds,next_retry_at, anderrors - Automatic Retry:
POST /jobs/{job_id}/failautomatically retries failed jobs up tomax_retrieswith exponential backoff (delay * 2^(retry_count - 1)) - Dead Letter Queue: Jobs that exhaust retries are added to the DLQ and can be inspected via
GET /jobs/dead-letter - Manual Retry:
POST /jobs/{job_id}/retrymoves a failed DLQ job back to pending with reset retry state - Retry Timing: Dispatch and auto-dispatch respect
next_retry_atso jobs are not redispatched before their backoff expires - Tests: 16 new retry/DLQ tests covering backoff, DLQ membership, retry endpoint, and dispatch timing
- Total Tests: 215 tests passing
- Control Plane UI: FastAPI serves a static HTML dashboard at
GET /with real-time job/worker monitoring - Dashboard Features: Job counts by status, worker health summary, auto-dispatch and health check buttons
- Jobs Tab: Filterable job list with status badges, progress bars, and action buttons (dispatch, cancel, retry)
- Workers Tab: Worker list with capabilities, current job assignment, and heartbeat actions
- Create Tab: Forms to submit new jobs and register workers with JSON capability definitions
- Auto-Refresh: Dashboard polls the API every 5 seconds for live updates
- Static Assets: CSS and JavaScript served from
gridlock/static/via FastAPIStaticFiles - Tests: 6 new UI tests covering root endpoint, static file serving, and Docker health check compatibility
- Dockerfile: Multi-stage build with Python 3.11 slim, installs dependencies from
pyproject.toml, exposes port 8000 - Docker Compose: Full stack deployment with
redisandgridlockservices, health checks, and persistent Redis volume - Environment:
REDIS_URLconfigured to connect to Redis service within Docker network - Health Checks: Docker health check pings
/healthendpoint; Redis health check usesredis-cli ping - Run:
docker compose up --buildstarts the complete stack
- Python 3.11+
- Redis (or Docker)
cd gridlock
pip install -e ".[dev]"
uvicorn gridlock.main:app --reloaddocker compose up --buildVisit http://localhost:8000 for the control plane UI.
See PLAN.md for detailed architecture decisions and implementation notes.
Apache-2.0, see LICENSE.
If this project saved you time, solved a problem, or just made your day a little more neon, you can fuel the next one:

