Skip to content

feat(api): migrate from Celery to RQ and expose queue position#143

Merged
vvatelot merged 5 commits into
mainfrom
feat/rq-queue-status-107
Jul 7, 2026
Merged

feat(api): migrate from Celery to RQ and expose queue position#143
vvatelot merged 5 commits into
mainfrom
feat/rq-queue-status-107

Conversation

@vvatelot

@vvatelot vvatelot commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

Closes #107

Migrates the Ecoindex API task backend from Celery to RQ, which allows exposing queue status information that Celery does not provide.

When submitting a new analysis or polling a pending task, the API now returns:

  • queue_position — position in the waiting queue (0 = next to run, null when running or completed)
  • tasks_in_progress — number of tasks currently being processed on the queue

API changes

  • GET /v1/tasks/ecoindexes/{id} response includes queue_position and tasks_in_progress while the task is pending
  • Task enqueueing, status polling, and cancellation are now backed by RQ jobs
  • OpenAPI schema updated accordingly

Infrastructure & dev experience

  • Replaced Celery worker with RQ workers (ecoindex and ecoindex_batch queues)
  • Removed Flower service from Docker Compose; added RQ Dashboard for local monitoring (task start-rq-dashboard on port 9181)
  • Added start_rq_workers.sh (shared between Docker and local dev) and wait_redis.py for reliable Redis discovery in dev
  • New settings: RQ_FAILURE_TTL, RQ_JOB_TIMEOUT, RQ_RESULT_TTL, RQ_WORKERS

Test plan

  • Start local stack with task start-dev and verify API, worker, and RQ dashboard are running
  • Submit a new analysis via POST /v1/tasks/ecoindexes/ and confirm a job ID is returned
  • Poll GET /v1/tasks/ecoindexes/{id} while pending and verify queue_position and tasks_in_progress are present
  • Submit multiple analyses and confirm queue_position increases for later tasks
  • Wait for completion and verify status: SUCCESS with ecoindex_result
  • Verify worker health endpoint reports RQ workers correctly
  • Build and run the Docker worker image with RQ_WORKERS > 1
  • Test batch task enqueueing and status polling

Made with Cursor

Replace Celery with RQ to allow reporting pending task position and
in-progress count in task status responses, resolving #107.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation API tooling components labels Jul 6, 2026
@vvatelot vvatelot self-assigned this Jul 6, 2026
vvatelot and others added 2 commits July 6, 2026 15:01
Avoid resolving the Redis host when loading the API Taskfile so CI tasks
like project-check can run without a Redis instance.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add explicit enqueue settings typing for mypy and remove an unused
import in the Redis helper so quality checks pass again.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Coverage PR 143

Branch coverage •
FileStmtsMissCoverMissing
components/ecoindex/config
   settings.py260100% 
TOTAL72623068% 

vvatelot added 2 commits July 7, 2026 12:59
…etup

- Changed RQ-dashboard dependency from a Git URL to a PyPI source in multiple configuration files for consistency.
- Enhanced devcontainer configuration by adding host mapping and forwarding ports for better development experience.
- Updated Dockerfile to include docker-compose-plugin for improved container management.
- Adjusted task scripts to reference the correct path for Redis wait script and added a new script for cleaning stale RQ workers.
- Made database migration scripts more robust by checking for existing columns before adding or dropping them.
- Changed the parameter type of the `is_stale` function from `Worker` to `BaseWorker` to align with the updated RQ library structure.
@vvatelot vvatelot merged commit a0e322c into main Jul 7, 2026
6 checks passed
@vvatelot vvatelot deleted the feat/rq-queue-status-107 branch July 7, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API components documentation Improvements or additions to documentation tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: API response with pending tasks when requesting new analysis

1 participant