[notif] Add clean up timer

This commit is contained in:
2026-03-20 13:06:30 -04:00
parent 470b7cbab5
commit 12b278e22e

View File

@ -4,6 +4,7 @@ use crate::{Error, SharedEnv};
use tokio::select; use tokio::select;
use tokio::sync::{broadcast, mpsc, oneshot}; use tokio::sync::{broadcast, mpsc, oneshot};
use tokio::task::spawn_local; use tokio::task::spawn_local;
use tokio::time::{interval, Duration};
use tracing::{debug, error, info, trace, warn}; use tracing::{debug, error, info, trace, warn};
#[derive(Debug)] #[derive(Debug)]
@ -138,8 +139,15 @@ struct SubscriptionActor {
impl SubscriptionActor { impl SubscriptionActor {
async fn run(mut self) { async fn run(mut self) {
let mut cleanup_timer = interval(Duration::from_secs(3600));
loop { loop {
select! { 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() => { Ok(event) = self.listener.events.recv() => {
debug!(?event, "received listener event"); debug!(?event, "received listener event");
match event { match event {