-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
267 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,3 +234,4 @@ api = "" | |
events = "" | ||
files = "" | ||
proxy = "" | ||
crond = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
use revolt_config::configure; | ||
use revolt_database::DatabaseInfo; | ||
use revolt_result::Result; | ||
use tasks::{file_deletion, prune_dangling_files}; | ||
use tokio::try_join; | ||
|
||
pub mod tasks; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
configure!(crond); | ||
|
||
let db = DatabaseInfo::Auto.connect().await.expect("database"); | ||
try_join!( | ||
file_deletion::task(db.clone()), | ||
prune_dangling_files::task(db) | ||
) | ||
.map(|_| ()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::time::Duration; | ||
|
||
use log::info; | ||
use revolt_database::Database; | ||
use revolt_files::delete_from_s3; | ||
use revolt_result::Result; | ||
use tokio::time::sleep; | ||
|
||
pub async fn task(db: Database) -> Result<()> { | ||
loop { | ||
let files = db.fetch_deleted_attachments().await?; | ||
|
||
for file in files { | ||
let count = db | ||
.count_file_hash_references(file.hash.as_ref().expect("no `hash` present")) | ||
.await?; | ||
|
||
// No other files reference this file on disk anymore | ||
if count <= 1 { | ||
let file_hash = db | ||
.fetch_attachment_hash(file.hash.as_ref().expect("no `hash` present")) | ||
.await?; | ||
|
||
// Delete from S3 | ||
delete_from_s3(&file_hash.bucket_id, &file_hash.path).await?; | ||
|
||
// Delete the hash | ||
db.delete_attachment_hash(&file_hash.id).await?; | ||
info!("Deleted file hash {}", file_hash.id); | ||
} | ||
|
||
// Delete the file | ||
db.delete_attachment(&file.id).await?; | ||
info!("Deleted file {}", file.id); | ||
} | ||
|
||
sleep(Duration::from_secs(60)).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod file_deletion; | ||
pub mod prune_dangling_files; |
Oops, something went wrong.