[notif] Add clean up timer
This commit is contained in:
@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user