reminder: file_path delivery + extract scheduler into own module

This commit is contained in:
damocles 2026-05-17 11:05:29 +02:00
parent f2484b5e78
commit 6ce85bd6f2
4 changed files with 181 additions and 42 deletions

View file

@ -21,6 +21,7 @@ mod manager_server;
mod meta;
mod migrate;
mod operator_questions;
mod reminder_scheduler;
mod server;
use coordinator::Coordinator;
@ -86,12 +87,6 @@ enum Cmd {
Deny { id: i64 },
}
/// Per-tick cap on reminders the scheduler delivers. Anything over this
/// stays due in the table and gets picked up on the next 5s tick — keeps
/// a 10k-deep backlog from flooding the broker (or hogging its mutex) in
/// one shot.
const REMINDER_BATCH_LIMIT: u64 = 100;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
@ -171,41 +166,9 @@ async fn main() -> Result<()> {
// when a previously-running container goes away without an
// operator-initiated transient state.
crash_watch::spawn(coord.clone());
// Reminder scheduler: checks for due reminders every 5 seconds,
// delivers them atomically (insert inbox + mark sent in one
// sqlite transaction so a transient failure on the second step
// can never produce a duplicate next tick). Per-cycle batch
// limit caps the burst — leftover reminders stay due and get
// picked up on the next tick instead of monopolising the broker
// mutex.
let reminder_coord = coord.clone();
tokio::spawn(async move {
loop {
match reminder_coord
.broker
.get_due_reminders(REMINDER_BATCH_LIMIT)
{
Ok(reminders) => {
for (agent, id, message, _file_path) in reminders {
if let Err(e) =
reminder_coord.broker.deliver_reminder(id, &agent, &message)
{
tracing::warn!(
reminder_id = id,
%agent,
error = ?e,
"failed to deliver reminder"
);
}
}
}
Err(e) => {
tracing::warn!(error = ?e, "failed to query due reminders");
}
}
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
}
});
// Reminder scheduler: drains due reminders + handles
// file_path payload persistence. See reminder_scheduler.rs.
reminder_scheduler::spawn(coord.clone());
let dash_coord = coord.clone();
tokio::spawn(async move {
if let Err(e) = dashboard::serve(dashboard_port, dash_coord).await {