Submits long-running work to a background worker so the API responds instantly, then lets clients poll for the result — the same pattern as Celery + Redis/RabbitMQ, built here with Python's built-in threading and queue so it runs with zero extra infrastructure.
POST /api/jobs— submit a job, get a job ID back immediately (202 Accepted)- Background worker thread processes jobs from a queue
GET /api/jobs/<id>— poll job status:queued→processing→completed/failed- Job history persisted in SQLite
Flask · Python threading/queue · SQLite
pip install flask
python app.pycurl -X POST http://localhost:5004/api/jobs -H "Content-Type: application/json" \
-d '{"job_type":"word_count","payload":"the quick brown fox jumps"}'
# -> {"job_id": "e21a...", "status": "queued"}
curl http://localhost:5004/api/jobs/e21a...
# poll again after ~2s -> {"status": "completed", "result": "word_count=5"}Replace queue.Queue() with a Celery app + Redis broker, and worker_loop becomes a @celery.task. The API contract (POST returns immediately, GET polls status) is identical — this project demonstrates the pattern without needing a broker running.