refactor(auth): LoginDeps, RegisterDeps, RefreshDeps, RegisterAndLoginDeps, RefreshSessionCleanupJob

This commit is contained in:
2026-06-11 22:58:42 +02:00
parent 70d1f10e3d
commit 9ca5ada924
18 changed files with 359 additions and 232 deletions

View File

@@ -1,28 +1,30 @@
use std::sync::Arc;
use std::time::Duration;
use async_trait::async_trait;
use domain::{errors::DomainError, ports::PeriodicJob};
use crate::context::AppContext;
use domain::{
errors::DomainError,
ports::{PeriodicJob, RefreshSessionRepository},
};
pub struct RefreshSessionCleanupJob {
ctx: AppContext,
refresh_session: Arc<dyn RefreshSessionRepository>,
}
impl RefreshSessionCleanupJob {
pub fn new(ctx: AppContext) -> Self {
Self { ctx }
pub fn new(refresh_session: Arc<dyn RefreshSessionRepository>) -> Self {
Self { refresh_session }
}
}
#[async_trait]
impl PeriodicJob for RefreshSessionCleanupJob {
fn interval(&self) -> Duration {
Duration::from_secs(86400)
Duration::from_secs(3600)
}
async fn run(&self) -> Result<(), DomainError> {
let n = self.ctx.repos.refresh_session.delete_expired().await?;
let n = self.refresh_session.delete_expired().await?;
if n > 0 {
tracing::info!("refresh session cleanup: removed {n} expired sessions");
}