diff --git a/ntfy-daemon/src/subscription.rs b/ntfy-daemon/src/subscription.rs index 98f6129..d0ca5fe 100644 --- a/ntfy-daemon/src/subscription.rs +++ b/ntfy-daemon/src/subscription.rs @@ -4,6 +4,7 @@ use crate::{Error, SharedEnv}; use tokio::select; use tokio::sync::{broadcast, mpsc, oneshot}; use tokio::task::spawn_local; +use tokio::time::{interval, Duration}; use tracing::{debug, error, info, trace, warn}; #[derive(Debug)] @@ -138,8 +139,15 @@ struct SubscriptionActor { impl SubscriptionActor { async fn run(mut self) { + let mut cleanup_timer = interval(Duration::from_secs(3600)); loop { select! { + _ = cleanup_timer.tick() => { + if self.model.retention_hours > 0 { + debug!(topic=?self.model.topic, "running retention cleanup"); + let _ = self.env.db.cleanup_messages(&self.model.server, &self.model.topic); + } + } Ok(event) = self.listener.events.recv() => { debug!(?event, "received listener event"); match event {