Skip to content

Commit

Permalink
When scheduling, also consider task age to sort requested tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Jul 22, 2024
1 parent 27208b2 commit 36e07db
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dispatcher/backend/src/utils/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ def get_reqs_doable_by(session: so.Session, worker: dbm.Worker) -> List[Dict[str
"""cursor of RequestedTasks() doable by a worker using all its resources
- sorted by priority
- sorted by duration (longest first)"""
- sorted by duration (longest first)
- sorted by updated_at (task requested long ago first, mandatory for zimit farm)
"""

def get_document(task: dbm.RequestedTask):
return {
Expand Down Expand Up @@ -351,7 +353,7 @@ def get_document(task: dbm.RequestedTask):
return list(
sorted(
map(get_document, session.execute(stmt).scalars()),
key=lambda x: (-x["priority"], -x["duration"]["value"]),
key=lambda x: (-x["priority"], -x["duration"]["value"], x["updated_at"]),
)
)

Expand Down

0 comments on commit 36e07db

Please sign in to comment.