Skip to content

Conversation

@AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Jun 3, 2025

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 PoolWorker data structure, but then realized that is way more complicated than the obvious solution. So I thought dequeue, but that also gets complicated because there aren't good built-ins for this. On other other hand, OrderedDict is 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.

  • Worker Pool:
    • Use OrderedDict for WorkerData.workers to preserve order of workers (dispatcherd/service/pool.py).
    • Add WorkerData.move_to_end(worker_id) and call it in process_finished to rotate the finished worker to the end.
    • Handle missing worker in move_to_end gracefully with a warning (race-safe).
    • Update protocol WorkerData to include move_to_end (dispatcherd/protocols.py).
  • Imports:
    • Add OrderedDict import in pool.py.
  • Tests:
    • Add tests/unit/service/test_worker_order.py verifying workers reorder and dispatch to the longest-idle worker, and that move_to_end logs a warning if the worker was removed.

Written by Cursor Bugbot for commit 8b8afec. This will update automatically on new commits. Configure here.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 3, 2025

@AlanCoding AlanCoding marked this pull request as ready for review June 3, 2025 20:57
@AlanCoding AlanCoding requested a review from kdelee June 3, 2025 20:58
cursor[bot]

This comment was marked as outdated.

@sonarqubecloud
Copy link

@AlanCoding AlanCoding requested a review from thedoubl3j October 21, 2025 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worker rotation options

1 participant