Refactor job queue from RQ-style to Pythonic state management #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The job queue implementation mimicked RQ's interface with multiple
is_*properties (is_queued,is_started,is_finished,is_failed), each triggering separate database queries. This created unnecessary complexity and poor performance.Changes
Replaced
JobwithBuildJobclassget_state()method retrieves all state in one query instead of 4+ separate queriesupdate_meta()andupdate_status()methods replace property settersmetaproperty andsave_meta()for existing build.py codeSimplified API response building
build_job_response()function uses singleget_state(refresh=True)callreturn_job_v1()with its multiple property accessesBuild function updates
BuildRequestwithmodel_dump()for JSON compatibilityExample
Before:
After:
Net: -10 lines, 1 query instead of 4+, clearer intent.
Original prompt
Objective
Refactor the job queue implementation in PR #5 to use a cleaner, more Pythonic design instead of mimicking RQ's interface. The current implementation works but has unnecessary complexity from trying to match RQ's API style.
Current Implementation Issues
is_queued,is_started,is_finished,is_failedall require separate DB queriesProposed Refactoring
1. Simplify Job Class (
asu/job_queue.py)Replace the current
Jobclass with a cleaner design:2. Simplify API Response Building (
asu/routers/api.py)Replace the
return_job_v1()function with a cleaner implementation: