scheduler.py: Prioritise jobs from later queues

Previously, we were reversing the order of queues in
_schedule_queue_jobs() in an attempt to avoid resource starvation of
queues which share resource types. This was incorrect as the earlier
jobs were still ready first and so were scheduled first.

Instead we schedule jobs starting from the most recently ready. This
will mean that queues later in the scheduling process will always have
priority when they share a resource type with another queue.

This also fixes a bug in _sched() arising from the fact we were
removing items from waiting_jobs while iterating through it.
Aside from resulting in the loop having an O(n^2) complexity, this
results in skipping the job following the removed item in the
iteration.

This commit is related to issue #712
1 file changed