Skip to content

Commit

Permalink
Merge pull request #16 from wobcom/refactor/vicky/clean-ups
Browse files Browse the repository at this point in the history
vicky: made get_next_tasks more concise
  • Loading branch information
johannwagner authored Apr 23, 2024
2 parents 5569018 + 40d0f65 commit 5bc773e
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions vicky/src/lib/vicky/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,40 +118,31 @@ impl Scheduler {
Ok(s)
}

pub fn get_next_task(self) -> Option<Task> {
for task in self.tasks {
if task.status != TaskStatus::NEW {
continue;
}

if !task
.features
.iter()
.all(|feat| self.machine_features.contains(feat))
{
continue;
}

let mut has_conflicts = false;
fn is_unconstrained(&self, task: &Task) -> bool {
task.locks.iter().all(|lock| {
self.constraints
.get_lock_sum(lock)
.map_or(true, |ls| ls.can_add_lock(lock))
})
}

for lock in &task.locks {
let lock_sum = self.constraints.get_lock_sum(lock);
match lock_sum {
Some(ls) => {
if !ls.can_add_lock(lock) {
has_conflicts = true;
}
}
None => continue,
}
}
fn supports_all_features(&self, task: &Task) -> bool {
task.features
.iter()
.all(|feat| self.machine_features.contains(feat))
}

if !has_conflicts {
return Some(task);
}
}
fn should_pick_task(&self, task: &Task) -> bool {
task.status == TaskStatus::NEW
&& self.supports_all_features(task)
&& self.is_unconstrained(task)
}

None
pub fn get_next_task(mut self) -> Option<Task> {
self.tasks
.iter()
.position(|task| self.should_pick_task(task))
.map(|idx| self.tasks.remove(idx))
}
}

Expand Down

0 comments on commit 5bc773e

Please sign in to comment.