-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9549 from Turbo87/delete-crate-job
Extract `DeleteCrateFromStorage` background job
- Loading branch information
Showing
4 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::storage::FeedId; | ||
use crate::worker::Environment; | ||
use anyhow::Context; | ||
use crates_io_worker::BackgroundJob; | ||
use std::sync::Arc; | ||
use tokio::try_join; | ||
|
||
/// A background job that deletes all files associated with a crate from the storage backend. | ||
#[derive(Serialize, Deserialize)] | ||
pub struct DeleteCrateFromStorage { | ||
name: String, | ||
} | ||
|
||
impl DeleteCrateFromStorage { | ||
pub fn new(name: String) -> Self { | ||
Self { name } | ||
} | ||
} | ||
|
||
impl BackgroundJob for DeleteCrateFromStorage { | ||
const JOB_NAME: &'static str = "delete_crate_from_storage"; | ||
|
||
type Context = Arc<Environment>; | ||
|
||
async fn run(&self, ctx: Self::Context) -> anyhow::Result<()> { | ||
let name = &self.name; | ||
|
||
try_join!( | ||
async { | ||
info!("{name}: Deleting crate files from S3…"); | ||
let result = ctx.storage.delete_all_crate_files(name).await; | ||
result.context("Failed to delete crate files from S3") | ||
}, | ||
async { | ||
info!("{name}: Deleting readme files from S3…"); | ||
let result = ctx.storage.delete_all_readmes(name).await; | ||
result.context("Failed to delete readme files from S3") | ||
}, | ||
async { | ||
info!("{name}: Deleting RSS feed from S3…"); | ||
let feed_id = FeedId::Crate { name }; | ||
let result = ctx.storage.delete_feed(&feed_id).await; | ||
result.context("Failed to delete RSS feed from S3") | ||
} | ||
)?; | ||
|
||
info!("{name}: Successfully deleted crate from S3"); | ||
Ok(()) | ||
} | ||
} |
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