Skip to content

Commit

Permalink
fix(console): lint new tasks, not just when there is a stats update (c…
Browse files Browse the repository at this point in the history
…onsole-rs#126)

I was working on a lost waker lint, and noticed that the "coma" task
wasn't being linted, because it never sends another stats update. This
fixes it to lint tasks when we first get them, too.
  • Loading branch information
seanmonstar committed Sep 9, 2021
1 parent bc2b723 commit efdb2cf
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions console/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl State {
let mut stats_update = update.stats_update;
let new_list = &mut self.new_tasks;
new_list.clear();
let linters = &self.linters;

let metas = &mut self.metas;
let new_tasks = update.new_tasks.into_iter().filter_map(|mut task| {
Expand Down Expand Up @@ -214,26 +215,19 @@ impl State {
warnings: Vec::new(),
};
task.update();
task.lint(linters);
let task = Rc::new(RefCell::new(task));
new_list.push(Rc::downgrade(&task));
Some((id, task))
});
self.tasks.extend(new_tasks);
let linters = &self.linters;
for (id, stats) in stats_update {
if let Some(task) = self.tasks.get_mut(&id) {
let mut task = task.borrow_mut();
tracing::trace!(?task, "processing stats update for");
task.warnings.clear();
for lint in linters {
tracing::debug!(?lint, ?task, "checking...");
if let Some(lint) = lint.check(&*task) {
tracing::info!(?lint, ?task, "found a warning!");
task.warnings.push(lint)
}
}
task.stats = stats.into();
task.update();
task.lint(linters);
}
}
}
Expand Down Expand Up @@ -417,6 +411,17 @@ impl Task {
self.completed_for = 1;
}
}

fn lint(&mut self, linters: &[Linter<Task>]) {
self.warnings.clear();
for lint in linters {
tracing::debug!(?lint, task = ?self, "checking...");
if let Some(warning) = lint.check(self) {
tracing::info!(?warning, task = ?self, "found a warning!");
self.warnings.push(warning)
}
}
}
}

impl Details {
Expand Down

0 comments on commit efdb2cf

Please sign in to comment.