refactor: split jobs.rs into per-context modules
This commit is contained in:
31
crates/application/src/jobs/refresh_session_cleanup.rs
Normal file
31
crates/application/src/jobs/refresh_session_cleanup.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use domain::{errors::DomainError, ports::PeriodicJob};
|
||||
|
||||
use crate::context::AppContext;
|
||||
|
||||
pub struct RefreshSessionCleanupJob {
|
||||
ctx: AppContext,
|
||||
}
|
||||
|
||||
impl RefreshSessionCleanupJob {
|
||||
pub fn new(ctx: AppContext) -> Self {
|
||||
Self { ctx }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl PeriodicJob for RefreshSessionCleanupJob {
|
||||
fn interval(&self) -> Duration {
|
||||
Duration::from_secs(86400)
|
||||
}
|
||||
|
||||
async fn run(&self) -> Result<(), DomainError> {
|
||||
let n = self.ctx.repos.refresh_session.delete_expired().await?;
|
||||
if n > 0 {
|
||||
tracing::info!("refresh session cleanup: removed {n} expired sessions");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user