Wake the idle order service at the next effective GTD deadline
This commit is contained in:
@@ -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?,
|
||||
|
||||
Reference in New Issue
Block a user