Wake the idle order service at the next effective GTD deadline
This commit is contained in:
@@ -161,6 +161,20 @@ impl Exchange {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Time until the next pending GTD stops trading, measured on the database clock.
|
||||
pub fn next_gtd_expiry(&self) -> Result<Option<Duration>> {
|
||||
let (first, now): (Option<i64>, i64) = self.db.query_row(
|
||||
"SELECT MIN(expiration), CAST(unixepoch('subsec')*1000 AS INTEGER)
|
||||
FROM order_deadlines WHERE pending=1",
|
||||
[],
|
||||
|row| Ok((row.get(0)?, row.get(1)?)),
|
||||
)?;
|
||||
Ok(first.map(|stated| {
|
||||
let cutoff = stated.saturating_sub(60).saturating_mul(1000);
|
||||
Duration::from_millis(cutoff.saturating_sub(now).max(0) as u64)
|
||||
}))
|
||||
}
|
||||
|
||||
/// Read requested outcome books in one consistent database and resident-book snapshot.
|
||||
pub fn public_books(&mut self, tokens: &[String]) -> Result<Vec<Value>> {
|
||||
let tx = expiry::transaction(&self.db, TransactionBehavior::Deferred)?;
|
||||
|
||||
Reference in New Issue
Block a user