fix reminder tool issues: error on time overflow, optimize scheduler query

This commit is contained in:
damocles 2026-05-16 13:00:56 +02:00
parent bc27113967
commit 24eec69418
4 changed files with 90 additions and 48 deletions

View file

@ -253,6 +253,25 @@ impl Broker {
.context("query reminders")
}
/// Get all due reminders across all agents in a single query.
/// Returns a vec of (agent, id, message, file_path) tuples.
pub fn get_all_due_reminders(&self) -> Result<Vec<(String, i64, String, Option<String>)>> {
let conn = self.conn.lock().unwrap();
let mut stmt = conn.prepare(
"SELECT agent, id, message, file_path FROM reminders WHERE due_at <= ?1 AND sent_at IS NULL ORDER BY agent, due_at ASC"
)?;
let rows = stmt.query_map(params![now_unix()], |row| {
Ok((
row.get::<_, String>(0)?,
row.get::<_, i64>(1)?,
row.get::<_, String>(2)?,
row.get::<_, Option<String>>(3)?,
))
})?;
rows.collect::<rusqlite::Result<Vec<_>>>()
.context("query all due reminders")
}
/// Mark a reminder as sent (delivered).
pub fn mark_reminder_sent(&self, id: i64) -> Result<()> {
let conn = self.conn.lock().unwrap();