Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

holger-estate-front/src/live.rs

//! **The front's own live slot on trial** (L20; jera jobs since L21): after a live update
//! re-exec'd the front into its new slot, the new app confirms it once the web face has served
//! for [`holger_live::CONFIRM_AFTER`]; not serving by [`holger_live::CONFIRM_DEADLINE`], it
//! re-execs (korp-start rolls the slot back). Each look is a `live.trial` jera job at High
//! priority on the front's own live ledger (`<root>/live/jobs`, [`holger_live::trial`]), as the
//! front's other duties (`front.recharge`) are jobs; nothing on trial, nothing is queued.

use std::path::Path;
use std::sync::Arc;

use holger_live::LiveSlot;

pub use holger_live::trial::LOOK_EVERY;

/// **Watch the trial** of `slot`, asking `serving` whether the front serves; the jobs are kept
/// under `root`. Must run inside a runtime.
pub fn watch_trial(slot: Arc<LiveSlot>, serving: fn() -> bool, root: &Path) {
    if !slot.on_trial() {
        return;
    }
    tracing::warn!("live update: this front runs on TRIAL — it confirms after serving {} s, or is rolled back at {} s (jera job {})", holger_live::CONFIRM_AFTER.as_secs(), holger_live::CONFIRM_DEADLINE.as_secs(), holger_live::trial::KIND_TRIAL);
    let roll_back: holger_live::trial::RollBack = Box::new(|| {
        tracing::error!(
            "live update: the new app did not serve within {} s — re-exec, korp-start rolls back",
            holger_live::CONFIRM_DEADLINE.as_secs()
        );
        #[cfg(target_os = "linux")]
        tracing::error!(
            "live update: the rollback re-exec failed: {}",
            holger_live::appliance::reexec_now()
        );
    });
    let jobs = root.join(holger_live::trial::JOBS_REL);
    if holger_live::trial::start(slot, Box::new(serving), &jobs, roll_back).is_none() {
        tracing::error!(jobs = %jobs.display(), "live update: the trial's jobs did not start: the slot is not confirmed — the next start rolls it back");
    }
}