hive-c0re: optional reset-timer on manual fire-now for recurring schedules
This commit is contained in:
parent
513c828ab2
commit
b6aeaf0b57
4 changed files with 89 additions and 17 deletions
|
|
@ -261,6 +261,10 @@ pub struct FireNowReport {
|
|||
/// schedules never auto-cancel on manual fire — they keep
|
||||
/// their cadence).
|
||||
pub one_shot_consumed: bool,
|
||||
/// Whether this manual fire re-armed a recurring schedule's timer
|
||||
/// (`next_fire_at = now + interval`). `true` only when the caller
|
||||
/// passed `reset_timer` AND the schedule is recurring.
|
||||
pub timer_reset: bool,
|
||||
}
|
||||
|
||||
/// Manual / out-of-band fire of a scheduled prompt ("fire now"
|
||||
|
|
@ -275,12 +279,18 @@ pub struct FireNowReport {
|
|||
/// the dashboard's per-target last-result column can distinguish
|
||||
/// scheduled fires from operator-initiated ones at a glance.
|
||||
///
|
||||
/// `reset_timer` re-arms a *recurring* schedule's countdown from now
|
||||
/// (`next_fire_at = now + interval`) after the fan-out — the dashboard
|
||||
/// fire-now dialog's "reset timer" checkbox. It's a no-op for one-shots
|
||||
/// (still consumed) and when `false` (today's default: cadence intact).
|
||||
///
|
||||
/// Returns Err if the schedule is missing, cancelled, or fully
|
||||
/// drained of active targets — the dashboard can surface those
|
||||
/// as plain 4xxs instead of pretending to fire a phantom row.
|
||||
pub async fn fire_now(
|
||||
coord: &std::sync::Arc<Coordinator>,
|
||||
schedule_id: i64,
|
||||
reset_timer: bool,
|
||||
) -> anyhow::Result<FireNowReport> {
|
||||
let now = now_unix();
|
||||
let schedule = coord
|
||||
|
|
@ -303,6 +313,7 @@ pub async fn fire_now(
|
|||
failed: 0,
|
||||
missing: 0,
|
||||
one_shot_consumed: false,
|
||||
timer_reset: false,
|
||||
};
|
||||
for target_row in &schedule.targets {
|
||||
if target_row.cancelled_at_unix.is_some() {
|
||||
|
|
@ -352,15 +363,28 @@ pub async fn fire_now(
|
|||
tracing::warn!(error = ?e, schedule = schedule_id, %target, "record_target_result failed");
|
||||
}
|
||||
}
|
||||
if schedule.interval_seconds.is_none() {
|
||||
// One-shot is consumed by the manual fire. Recurring
|
||||
// schedules stay untouched — their cadence is the whole
|
||||
// point and a manual fire is meant to be additive.
|
||||
if let Err(e) = coord.scheduled_prompts.cancel_all(schedule_id) {
|
||||
tracing::warn!(error = ?e, schedule = schedule_id, "cancel_all after one-shot manual fire failed");
|
||||
} else {
|
||||
report.one_shot_consumed = true;
|
||||
match schedule.interval_seconds {
|
||||
None => {
|
||||
// One-shot is consumed by the manual fire. (reset_timer is
|
||||
// moot here — there's no recurring cadence to re-arm.)
|
||||
if let Err(e) = coord.scheduled_prompts.cancel_all(schedule_id) {
|
||||
tracing::warn!(error = ?e, schedule = schedule_id, "cancel_all after one-shot manual fire failed");
|
||||
} else {
|
||||
report.one_shot_consumed = true;
|
||||
}
|
||||
}
|
||||
Some(interval) if reset_timer => {
|
||||
// Recurring + operator asked to reset: re-arm the countdown
|
||||
// from now (now + interval), not along the existing cadence.
|
||||
let next = now.saturating_add(i64::try_from(interval).unwrap_or(i64::MAX));
|
||||
if let Err(e) = coord.scheduled_prompts.set_next_fire(schedule_id, next) {
|
||||
tracing::warn!(error = ?e, schedule = schedule_id, "set_next_fire after manual fire reset failed");
|
||||
} else {
|
||||
report.timer_reset = true;
|
||||
}
|
||||
}
|
||||
// Recurring without reset: cadence stays intact (additive fire).
|
||||
Some(_) => {}
|
||||
}
|
||||
Ok(report)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue