Worker rotation via the longest-idle criteria #181
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.



Fixes #156
This doesn't make it configurable, because I see no need to make it configurable. Workers are interchangeable, and this is the only reason we have to have any selection criteria for free workers (postgres connection timeout).
I thought about tracking the last-finished timestamp in the
PoolWorkerdata structure, but then realized that is way more complicated than the obvious solution. So I thoughtdequeue, but that also gets complicated because there aren't good built-ins for this. On other other hand,OrderedDictis just 💯Finished a task? Go to the end of the line.
Need a worker to start a task? Look starting from the front of the line.
Note
Implements longest-idle worker selection by ordering workers and rotating finished workers to the end, with tests and race-safe handling.
OrderedDictforWorkerData.workersto preserve order of workers (dispatcherd/service/pool.py).WorkerData.move_to_end(worker_id)and call it inprocess_finishedto rotate the finished worker to the end.move_to_endgracefully with a warning (race-safe).WorkerDatato includemove_to_end(dispatcherd/protocols.py).OrderedDictimport inpool.py.tests/unit/service/test_worker_order.pyverifying workers reorder and dispatch to the longest-idle worker, and thatmove_to_endlogs a warning if the worker was removed.Written by Cursor Bugbot for commit 8b8afec. This will update automatically on new commits. Configure here.