diff options
author | Jeremy Lin <[email protected]> | 2021-04-02 20:16:49 -0700 |
---|---|---|
committer | Jeremy Lin <[email protected]> | 2021-04-05 23:07:15 -0700 |
commit | 73ff8d79f70b36483d1d33587cdc9549c8e472bd (patch) | |
tree | 4bda2dc39f4e6f0c7738e4f94ecc4ca0e75582bd /src/api/core/sends.rs | |
parent | a82c04910f259fd0296085cc9aa9280df5881a87 (diff) | |
download | vaultwarden-73ff8d79f70b36483d1d33587cdc9549c8e472bd.tar.gz vaultwarden-73ff8d79f70b36483d1d33587cdc9549c8e472bd.zip |
Add a generic job scheduler
Also rewrite deletion of old sends using the job scheduler.
Diffstat (limited to 'src/api/core/sends.rs')
-rw-r--r-- | src/api/core/sends.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/api/core/sends.rs b/src/api/core/sends.rs index ec6809a2..3cd568c5 100644 --- a/src/api/core/sends.rs +++ b/src/api/core/sends.rs @@ -9,7 +9,7 @@ use serde_json::Value; use crate::{ api::{ApiResult, EmptyResult, JsonResult, JsonUpcase, Notify, UpdateType}, auth::{Headers, Host}, - db::{models::*, DbConn}, + db::{models::*, DbConn, DbPool}, CONFIG, }; @@ -27,21 +27,13 @@ pub fn routes() -> Vec<rocket::Route> { ] } -pub fn start_send_deletion_scheduler(pool: crate::db::DbPool) { - std::thread::spawn(move || { - loop { - if let Ok(conn) = pool.get() { - info!("Initiating send deletion"); - for send in Send::find_all(&conn) { - if chrono::Utc::now().naive_utc() >= send.deletion_date { - send.delete(&conn).ok(); - } - } - } - - std::thread::sleep(std::time::Duration::from_secs(3600)); - } - }); +pub fn purge_sends(pool: DbPool) { + debug!("Purging sends"); + if let Ok(conn) = pool.get() { + Send::purge(&conn); + } else { + error!("Failed to get DB connection while purging sends") + } } #[derive(Deserialize)] |