Skip to content

Commit

Permalink
jobs/delete_crate: Run deletions concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Oct 1, 2024
1 parent 087cd6b commit e021fe8
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/worker/jobs/delete_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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)]

Check warning on line 9 in src/worker/jobs/delete_crate.rs

View check run for this annotation

Codecov / codecov/patch

src/worker/jobs/delete_crate.rs#L9

Added line #L9 was not covered by tests
Expand All @@ -24,18 +25,24 @@ impl BackgroundJob for DeleteCrateFromStorage {
async fn run(&self, ctx: Self::Context) -> anyhow::Result<()> {
let name = &self.name;

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")?;

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")?;

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")?;
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")
}
)?;

Check warning on line 45 in src/worker/jobs/delete_crate.rs

View check run for this annotation

Codecov / codecov/patch

src/worker/jobs/delete_crate.rs#L25-L45

Added lines #L25 - L45 were not covered by tests

info!("{name}: Successfully deleted crate from S3");
Ok(())
Expand Down

0 comments on commit e021fe8

Please sign in to comment.