Skip to content

Commit

Permalink
Merge pull request #999 from openzim/scheduling_prio
Browse files Browse the repository at this point in the history
When scheduling, also consider task age to sort requested tasks
  • Loading branch information
benoit74 authored Jul 22, 2024
2 parents 27208b2 + 36e07db commit 9ad012b
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 9ad012b

Please sign in to comment.