diff options
Diffstat (limited to 'src/ops.rs')
| -rw-r--r-- | src/ops.rs | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -43,7 +43,21 @@ pub struct Metrics { } impl Metrics { + /// The metrics report computes it internally; a test checks the arithmetic. + /// + /// Module-internal in a production build, `pub` only under `test-support`: + /// one body behind two visibility declarations, exactly one of which compiles. + #[cfg(feature = "test-support")] pub fn build_success_rate(&self) -> f64 { + Self::build_success_rate_impl(self) + } + + #[cfg(not(feature = "test-support"))] + pub(crate) fn build_success_rate(&self) -> f64 { + Self::build_success_rate_impl(self) + } + + fn build_success_rate_impl(&self) -> f64 { match self.succeeded + self.failed { 0 => 1.0, n => self.succeeded as f64 / n as f64, @@ -307,7 +321,19 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention Ok(report) } -pub const STAGING_GRACE_SECS: i64 = 3600; +/// How long a file may sit in staging before the sweep considers it abandoned. +/// +/// The value lives once, in a private const, so the two visibility aliases below +/// cannot drift apart. Production reaches the grace period through +/// `run_maintenance`, which is the only thing that sweeps; a test that pins the +/// number is a test, not a caller. +const STAGING_GRACE_SECS_VALUE: i64 = 3600; + +#[cfg(feature = "test-support")] +pub const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE; + +#[cfg(not(feature = "test-support"))] +pub(crate) const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE; pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathBuf>> { let mut out = Vec::new(); @@ -329,7 +355,21 @@ pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathB Ok(out) } +/// The maintenance pass calls it; a test pins what it sweeps without running the whole pass. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { + sweep_staging_impl(cfg, db, grace_secs) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { + sweep_staging_impl(cfg, db, grace_secs) +} + +fn sweep_staging_impl(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { let root = cfg.staging_dir(); let Ok(entries) = std::fs::read_dir(&root) else { return Ok((0, 0)) }; let now = time::now(); |
