broker: hourly vacuum of delivered messages older than 30 days
undelivered rows are always kept regardless of age (still in flight). sweep runs immediately on serve start then every hour. logs row count when non-zero. keep_secs is hard-coded for now (30 days); can be config-driven later if a host wants to retain more / less for audit.
This commit is contained in:
parent
a9ed33d94f
commit
6d52f67292
3 changed files with 31 additions and 2 deletions
|
|
@ -171,6 +171,21 @@ impl Broker {
|
|||
}
|
||||
}
|
||||
|
||||
/// Delete delivered messages older than `older_than_secs`. Undelivered
|
||||
/// rows are always kept regardless of age — those are still in flight
|
||||
/// from the broker's POV. Returns the number of rows removed.
|
||||
pub fn vacuum_delivered(&self, older_than_secs: i64) -> Result<u64> {
|
||||
let cutoff = now_unix() - older_than_secs;
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let n = conn.execute(
|
||||
"DELETE FROM messages
|
||||
WHERE delivered_at IS NOT NULL
|
||||
AND delivered_at < ?1",
|
||||
params![cutoff],
|
||||
)?;
|
||||
Ok(u64::try_from(n).unwrap_or(0))
|
||||
}
|
||||
|
||||
pub fn recv(&self, recipient: &str) -> Result<Option<Message>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let row: Option<(i64, String, String, String)> = conn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue