Repository navigation
Refactor _executable_task_instances_to_queued to make logic more readable - #66878
Merged
Merged
Conversation
jedcunningham
approved these changes
May 13, 2026
This comment was marked as resolved.
This comment was marked as resolved.
ashb
force-pushed
the
scheduler-enqueue-readability
branch
from
May 14, 2026 11:21
007fd8b to
0e16ac2
Compare
jscheffl
reviewed
Jun 14, 2026
jscheffl
approved these changes
Jun 14, 2026
jscheffl
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the break-up of the code and logic. That makes totally sense and due to the good pydoc makes it much more readable.
two nit from my side, then LGTM, hope we have this in 3.3.0? Would be cool as a clean start on a new minor.
ashb
commented
Jun 23, 2026
ashb
commented
Jun 23, 2026
Contributor
|
@ashb could you help resolving conflicts? |
…stances Split the monolithic `_executable_task_instances_to_queued` into two focused methods: - `_acquire_pool_capacity`: takes the advisory lock and reads pool utilisation via SELECT FOR UPDATE. Returns (pools, max_tis, starved_pools) so callers can short-circuit when all pools are full before doing any TI selection work. - `_select_task_instances_to_queue`: given pre-computed pool capacity, selects eligible SCHEDULED TIs and moves them to QUEUED. Accepts the pools dict and starved_pools set as parameters, making it directly testable without needing a real lock or DB pool read. `_critical_section_enqueue_task_instances` now calls these two methods in sequence, making the two-phase structure (acquire capacity, then select and queue) visible at the orchestration level. All test call sites updated to call `_select_task_instances_to_queue` directly with a `make_pool_stats()` helper, removing the dependency on pool row locking in unit tests.
ashb
force-pushed
the
scheduler-enqueue-readability
branch
from
September 23, 2026 09:53
0e16ac2 to
dd58747
Compare
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I was looking at the core scheduler logic, and the
_executable_task_instances_to_queuedwas rather large, and hard for even me to understand, and past me wrote a good chunk of it!This splits it into two (plus a helper) focused methods to aid readability:
_acquire_pool_capacity: takes the advisory lock (lifetime of the session, so longer than just this fn) and reads pool utilisation via SELECT FOR UPDATE. Returns (pools, max_tis, starved_pools) so caller can short-circuit when all pools are full before doing any TI selection work._select_task_instances_to_queue: given pre-computed pool capacity, selects eligible SCHEDULED TIs and moves them to QUEUED. Accepts the pools dict and starved_pools set as parameters, making it directly testable without needing a real lock or DB pool read. This uses the new_build_schedulable_tis_queryhelper fn to build the complex query._critical_section_enqueue_task_instancesnow calls these two methods in sequence, making the two-phase structure (acquire capacity, then select and queue) more explicit.All test call sites updated to call
_select_task_instances_to_queuedirectly with amake_pool_stats()helper, removing the dependency on pool row locking in unit tests.No behaviour changes, just refactoring.