hive-c0re: optional reset-timer on manual fire-now for recurring schedules

This commit is contained in:
damocles 2026-06-22 00:11:49 +02:00 committed by mara
commit b6aeaf0b57
4 changed files with 89 additions and 17 deletions

View file

@ -340,6 +340,20 @@ impl ScheduledPrompts {
Ok(skipped)
}
/// Set a schedule's `next_fire_at` to an absolute timestamp. Unlike
/// [`rearm`](Self::rearm) (which advances along the existing cadence
/// with catch-up), this writes the value verbatim — used by the
/// manual fire-now "reset timer" path to re-arm a recurring schedule
/// from now (`now + interval`).
pub fn set_next_fire(&self, id: i64, next_unix: i64) -> Result<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE scheduled_prompts SET next_fire_at_unix = ?1 WHERE id = ?2",
params![next_unix, id],
)?;
Ok(())
}
/// Partial-update an existing schedule's mutable fields.
/// Every scalar field is `Option<_>`; `None` means "leave the
/// existing value alone", `Some(_)` means "set it to this."
@ -684,6 +698,28 @@ mod tests {
assert_eq!(s.next_fire_at_unix, 460);
}
#[test]
fn set_next_fire_writes_absolute_value() {
let (_dir, db) = open();
// Recurring every 60s, first fire at t=100.
let id = db
.submit(&NewSchedule {
owner: "operator".into(),
targets: vec!["alice".into()],
body: "wake".into(),
first_fire_at_unix: 100,
interval_seconds: Some(60),
description: None,
source: ScheduleSource::Operator,
})
.expect("submit");
// Unlike rearm (cadence-aligned), set_next_fire writes verbatim —
// the manual fire-now "reset timer" path uses now + interval.
db.set_next_fire(id, 1_234).expect("set_next_fire");
let s = db.get(id).expect("get").expect("present");
assert_eq!(s.next_fire_at_unix, 1_234);
}
#[test]
fn rearm_advances_one_step_when_caught_up() {
let (_dir, db) = open();