Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/crates-admin/backfill_og_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn run(opts: Opts) -> Result<()> {
// Create batch of jobs
let jobs = crate_names
.into_iter()
.map(GenerateOgImage::new)
.map(GenerateOgImage::without_cdn_invalidation)
.map(|job| {
Ok((
background_jobs::job_type.eq(GenerateOgImage::JOB_NAME),
Expand Down
22 changes: 20 additions & 2 deletions src/worker/jobs/generate_og_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ use tracing::{error, info, instrument, warn};
#[derive(Serialize, Deserialize)]
pub struct GenerateOgImage {
crate_name: String,
invalidate_cdns: bool,
}

impl GenerateOgImage {
pub fn new(crate_name: String) -> Self {
Self { crate_name }
Self {
crate_name,
invalidate_cdns: true,
}
}

pub fn without_cdn_invalidation(crate_name: String) -> Self {
Self {
crate_name,
invalidate_cdns: false,
}
}
}

Expand Down Expand Up @@ -83,6 +94,13 @@ impl BackgroundJob for GenerateOgImage {
.upload_og_image(crate_name, image_bytes.into())
.await?;

info!("Successfully generated and uploaded OG image for crate {crate_name}");

if !self.invalidate_cdns {
info!("Skipping CDN invalidation for crate {crate_name}");
return Ok(());
}

// Invalidate CDN cache for the OG image
let og_image_path = format!("og-images/{crate_name}.png");

Expand All @@ -100,7 +118,7 @@ impl BackgroundJob for GenerateOgImage {
}
}

info!("Successfully generated and uploaded OG image for crate {crate_name}");
info!("CDN invalidation completed for crate {crate_name}");

Ok(())
}
Expand Down