Skip to content
athulya02studyPublic

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Background Job Queue

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.

Features

  • 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

Stack

Flask · Python threading/queue · SQLite

Run it

pip install flask
python app.py

Example usage

curl -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"}

Porting to Celery + Redis

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.

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages