Fix double-actioning in throttle

This commit is contained in:
Félix Saparelli 2021-08-23 03:12:23 +12:00
parent b42336cb74
commit 9b94f18890
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474

View file

@ -177,6 +177,12 @@ pub async fn worker(
Ok(None) => break,
Ok(Some(event)) => {
trace!(?event, "got event");
if set.is_empty() {
trace!("event is the first, resetting throttle window");
last = Instant::now();
}
set.push(event);
let elapsed = last.elapsed();
@ -247,6 +253,7 @@ async fn apply_outcome(
(Some(p), Outcome::Stop) => {
p.kill().await?;
p.wait().await?;
*process = None;
}
(p @ None, o @ Outcome::Stop)
| (p @ Some(_), o @ Outcome::Start)
@ -261,6 +268,7 @@ async fn apply_outcome(
// TODO: pre-spawn hook
debug!(grouped=%working.grouped, ?command, "spawning command");
let proc = if working.grouped {
Process::Grouped(command.group_spawn()?)
} else {
@ -270,6 +278,8 @@ async fn apply_outcome(
// TODO: post-spawn hook
*process = Some(proc);
// TODO: post-stop hook (immediately after *process* ends, not when Stop is applied)
}
}