cloudillo_auth/
cleanup.rs1use async_trait::async_trait;
7use serde::{Deserialize, Serialize};
8use std::sync::Arc;
9
10use cloudillo_core::scheduler::{Task, TaskId};
11
12use crate::prelude::*;
13
14#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct AuthCleanupTask;
20
21#[async_trait]
22impl Task<App> for AuthCleanupTask {
23 fn kind() -> &'static str {
24 "auth.cleanup"
25 }
26
27 fn build(_id: TaskId, _context: &str) -> ClResult<Arc<dyn Task<App>>> {
28 Ok(Arc::new(AuthCleanupTask))
29 }
30
31 fn serialize(&self) -> String {
32 String::new()
33 }
34
35 fn kind_of(&self) -> &'static str {
36 "auth.cleanup"
37 }
38
39 async fn run(&self, app: &App) -> ClResult<()> {
40 info!("Running auth cleanup task");
41
42 match app.auth_adapter.cleanup_expired_api_keys().await {
44 Ok(count) => {
45 if count > 0 {
46 info!("Cleaned up {} expired API keys", count);
47 }
48 }
49 Err(e) => {
50 warn!("Failed to cleanup expired API keys: {}", e);
51 }
52 }
53
54 match app.auth_adapter.cleanup_expired_verification_codes().await {
56 Ok(count) => {
57 if count > 0 {
58 info!("Cleaned up {} expired verification codes", count);
59 }
60 }
61 Err(e) => {
62 warn!("Failed to cleanup expired verification codes: {}", e);
63 }
64 }
65
66 if let Ok(store) = app.ext::<crate::qr_login::QrLoginStore>() {
68 let count = store.cleanup_expired();
69 if count > 0 {
70 info!("Cleaned up {} expired QR login sessions", count);
71 }
72 }
73
74 Ok(())
75 }
76}
77
78