Skip to main content

isothrum_runner/
reap.rs

1//! The reaper's half in the runner, so an abandoned run can't keep billing: [`Runner::expired`],
2//! the recorded runs whose lifetime ([`crate::RunOptions::lifetime`], recorded at `up` as the
3//! record's `expires_at`) passed and that may still hold something. Removing one is its `down`
4//! ([`Runner::reopen`], then [`crate::Running::down`]), which acts on what the run recorded.
5//!
6//! The sweep's schedule is the embedder's (every few minutes, say; the `isothrum reap` command
7//! sweeps once).
8
9use std::time::SystemTime;
10
11use crate::Result;
12use crate::runner::Runner;
13use crate::store::RunRecord;
14
15impl Runner {
16    /// The recorded runs whose expiry passed at `now` and whose last operation didn't leave them
17    /// absent: the reaper's input. Reads the store only.
18    ///
19    /// # Errors
20    ///
21    /// Fails as the store does when a record can't be read.
22    pub fn expired(&self, now: SystemTime) -> Result<Vec<RunRecord>> {
23        Ok(self.store.records()?.into_iter().filter(|r| r.expired(now)).collect())
24    }
25}
26
27#[cfg(test)]
28mod tests;