Fix action throttling
Specifically, on loop start the timeout would be for the full throttle duration,
which is not correct if some time has passed or the loop goes on recycle
@@ -107,19 +107,31 @@ pub async fn worker(
{ working.borrow().action_handler.take() }.ok_or(CriticalError::MissingHandler)?;
loop {
- let maxtime = working.borrow().throttle;
+ let maxtime = working.borrow().throttle.saturating_sub(last.elapsed());
+
+ if maxtime.is_zero() {
+ trace!("out of throttle on recycle");
+ } else {
+ trace!(?maxtime, "waiting for event");
match timeout(maxtime, events.recv()).await {
- Err(_timeout) => {}
+ Err(_timeout) => {
+ trace!("timed out");
+ }
Ok(None) => break,
Ok(Some(event)) => {
+ trace!(?event, "got event");
set.push(event);
- if last.elapsed() < working.borrow().throttle {
+ let elapsed = last.elapsed();
+ if elapsed < working.borrow().throttle {
+ trace!(?elapsed, "still within throttle window, cycling");
continue;
}
}
}
+ }
+ trace!("out of throttle, starting action process");
last = Instant::now();
let action = Action::new(set.drain(..).collect());
@@ -139,5 +151,7 @@ pub async fn worker(
let outcome = outcome.get().cloned().unwrap_or_default();
debug!(?outcome, "handler finished");
}
+
+ debug!("action worker finished");
Ok(())
}
