diff --git a/dispatcher/backend/src/utils/scheduling.py b/dispatcher/backend/src/utils/scheduling.py index 08f31708..94376d7d 100644 --- a/dispatcher/backend/src/utils/scheduling.py +++ b/dispatcher/backend/src/utils/scheduling.py @@ -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 { @@ -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"]), ) )