Wake the idle order service at the next effective GTD deadline

This commit is contained in:
2026-12-03 14:43:10 +08:00
parent 2a6332620c
commit 4262b7adaa
5 changed files with 38 additions and 5 deletions
+12 -2
View File
@@ -25,11 +25,21 @@ pub(crate) fn serve(
}
});
let interval = Duration::from_secs(5);
let mut next = Instant::now() + interval;
// New GTDs live at least two minutes, so rechecking within five seconds
// also catches orders added by another process before their cutoff.
let next_check = |exchange: &Exchange| -> Result<Instant> {
let start = Instant::now();
let wait = exchange
.next_gtd_expiry()?
.unwrap_or(interval)
.min(interval);
Ok(start + wait)
};
let mut next = next_check(engine)?;
loop {
if Instant::now() >= next {
engine.maintain()?;
next = Instant::now() + interval;
next = next_check(engine)?;
}
let line = match reader.recv_timeout(next.saturating_duration_since(Instant::now())) {
Ok(line) => line?,