chore: migrate authifier into codebase (#658)
Co-authored-by: izzy <me@insrt.uk> Signed-off-by: Zomatree <me@zomatree.live> Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
23
crates/daemons/crond/src/tasks/delete_accounts.rs
Normal file
23
crates/daemons/crond/src/tasks/delete_accounts.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use revolt_database::Database;
|
||||
use revolt_result::Result;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn task(db: Database, _: revolt_database::AMQP) -> Result<()> {
|
||||
loop {
|
||||
let accounts = db.fetch_accounts_due_for_deletion().await?;
|
||||
let count = accounts.len();
|
||||
|
||||
for mut account in accounts {
|
||||
let mut user = db.fetch_user(&account.id).await?;
|
||||
|
||||
user.delete(&db).await?;
|
||||
account.mark_deleted(&db).await?;
|
||||
}
|
||||
|
||||
log::info!("Deleted {count} accounts.");
|
||||
|
||||
sleep(Duration::from_hours(1)).await
|
||||
}
|
||||
}
|
||||
@@ -6,21 +6,17 @@ use revolt_files::delete_from_s3;
|
||||
use revolt_result::Result;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn task(db: Database) -> Result<()> {
|
||||
pub async fn task(db: Database, _: revolt_database::AMQP) -> Result<()> {
|
||||
loop {
|
||||
let files = db.fetch_deleted_attachments().await?;
|
||||
|
||||
for file in files {
|
||||
if let Some(hash) = &file.hash {
|
||||
let count = db
|
||||
.count_file_hash_references(hash)
|
||||
.await?;
|
||||
let count = db.count_file_hash_references(hash).await?;
|
||||
|
||||
// No other files reference this file on disk anymore
|
||||
if count <= 1 {
|
||||
let file_hash = db
|
||||
.fetch_attachment_hash(hash)
|
||||
.await?;
|
||||
let file_hash = db.fetch_attachment_hash(hash).await?;
|
||||
|
||||
// Delete from S3
|
||||
delete_from_s3(&file_hash.bucket_id, &file_hash.path).await?;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
pub mod delete_accounts;
|
||||
pub mod acks;
|
||||
pub mod file_deletion;
|
||||
pub mod prune_dangling_files;
|
||||
pub mod prune_members;
|
||||
pub mod prune_mfa_tickets;
|
||||
|
||||
@@ -6,7 +6,7 @@ use tokio::time::sleep;
|
||||
|
||||
use log::info;
|
||||
|
||||
pub async fn task(db: Database) -> Result<()> {
|
||||
pub async fn task(db: Database, _: revolt_database::AMQP) -> Result<()> {
|
||||
loop {
|
||||
// This could just be a single database query
|
||||
// ... but timestamps are inconsistently serialised
|
||||
|
||||
@@ -5,7 +5,7 @@ use revolt_database::Database;
|
||||
use revolt_result::Result;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn task(db: Database) -> Result<()> {
|
||||
pub async fn task(db: Database, _: revolt_database::AMQP) -> Result<()> {
|
||||
loop {
|
||||
let success = db.remove_dangling_members().await;
|
||||
if let Err(s) = success {
|
||||
|
||||
14
crates/daemons/crond/src/tasks/prune_mfa_tickets.rs
Normal file
14
crates/daemons/crond/src/tasks/prune_mfa_tickets.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use revolt_database::Database;
|
||||
use revolt_result::Result;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn task(db: Database) -> Result<()> {
|
||||
loop {
|
||||
let count = db.delete_expired_tickets().await?;
|
||||
log::info!("Pruned {count} expired MFA tickets");
|
||||
|
||||
sleep(Duration::from_mins(5)).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user