diff options
| author | soryu <soryu@soryu.co> | 2026-01-22 22:32:46 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-23 01:03:04 +0000 |
| commit | 1ed362424dafec690f919154f5116471951cda9c (patch) | |
| tree | 19c7ca9231887394a791223fe32a8ad335a687a8 /makima/src/server/mod.rs | |
| parent | 265f8cf14fec9d7116d09af49e4b48b357faceda (diff) | |
| download | soryu-1ed362424dafec690f919154f5116471951cda9c.tar.gz soryu-1ed362424dafec690f919154f5116471951cda9c.zip | |
Add patch checkpointing
Diffstat (limited to 'makima/src/server/mod.rs')
| -rw-r--r-- | makima/src/server/mod.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/makima/src/server/mod.rs b/makima/src/server/mod.rs index 0bc1b92..3a27513 100644 --- a/makima/src/server/mod.rs +++ b/makima/src/server/mod.rs @@ -248,6 +248,8 @@ const DAEMON_HEARTBEAT_TIMEOUT_SECS: i64 = 120; const ANONYMOUS_TASK_CLEANUP_INTERVAL_SECS: u64 = 24 * 60 * 60; /// Maximum age in days for anonymous tasks before cleanup const ANONYMOUS_TASK_MAX_AGE_DAYS: i32 = 7; +/// Interval for checkpoint patch cleanup (hourly) +const CHECKPOINT_PATCH_CLEANUP_INTERVAL_SECS: u64 = 3600; /// Run the HTTP server with graceful shutdown support. /// @@ -344,6 +346,47 @@ pub async fn run_server(state: SharedState, addr: &str) -> anyhow::Result<()> { } } }); + + // Clone pool for checkpoint patch cleanup + let checkpoint_patch_cleanup_pool = pool.clone(); + + // Initial cleanup of any expired checkpoint patches + match crate::db::repository::cleanup_expired_checkpoint_patches(&pool).await { + Ok(deleted) if deleted > 0 => { + tracing::info!( + deleted = deleted, + "Cleaned up expired checkpoint patches on startup" + ); + } + Err(e) => { + tracing::warn!(error = %e, "Failed to clean up expired checkpoint patches on startup"); + } + _ => {} + } + + // Spawn periodic checkpoint patch cleanup task (runs hourly) + tokio::spawn(async move { + let mut interval = tokio::time::interval( + std::time::Duration::from_secs(CHECKPOINT_PATCH_CLEANUP_INTERVAL_SECS) + ); + loop { + interval.tick().await; + match crate::db::repository::cleanup_expired_checkpoint_patches( + &checkpoint_patch_cleanup_pool, + ).await { + Ok(deleted) if deleted > 0 => { + tracing::info!( + deleted = deleted, + "Cleaned up expired checkpoint patches" + ); + } + Err(e) => { + tracing::warn!(error = %e, "Failed to clean up expired checkpoint patches"); + } + _ => {} + } + } + }); } let app = make_router(state); |
