From 9bf5166362f8496f7ab66c3b228cbf6e6828dbd8 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 4 Nov 2024 18:41:02 +0100 Subject: [PATCH 1/2] admin/upload_index: Remove redundant tokio runtime There is already an outer runtime, so we don't need this one anymore :) --- src/bin/crates-admin/upload_index.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bin/crates-admin/upload_index.rs b/src/bin/crates-admin/upload_index.rs index a03cf35dd6d..d2cba59ee57 100644 --- a/src/bin/crates-admin/upload_index.rs +++ b/src/bin/crates-admin/upload_index.rs @@ -1,9 +1,10 @@ use crate::dialoguer; -use anyhow::{anyhow, Context}; +use anyhow::anyhow; use crates_io::storage::Storage; use crates_io::tasks::spawn_blocking; use crates_io_index::{Repository, RepositoryConfig}; use indicatif::{ProgressBar, ProgressIterator, ProgressStyle}; +use tokio::runtime::Handle; #[derive(clap::Parser, Debug)] #[command( @@ -31,11 +32,6 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> { return Ok(()); } - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .context("Failed to initialize tokio runtime")?; - let pb = ProgressBar::new(files.len() as u64); pb.set_style(ProgressStyle::with_template( "{bar:60} ({pos}/{len}, ETA {eta})", @@ -59,7 +55,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> { } let contents = std::fs::read_to_string(&path)?; - rt.block_on(storage.sync_index(crate_name, Some(contents)))?; + Handle::current().block_on(storage.sync_index(crate_name, Some(contents)))?; } println!( From dda300ebb8ef8b3026c4b42d93593c9e6a0b1c49 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 4 Nov 2024 18:43:14 +0100 Subject: [PATCH 2/2] admin/render_readmes: Remove redundant tokio runtime There is already an outer runtime, so we don't need this one anymore :) --- src/bin/crates-admin/render_readmes.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/bin/crates-admin/render_readmes.rs b/src/bin/crates-admin/render_readmes.rs index 29868b1566f..2dd5dfb22e3 100644 --- a/src/bin/crates-admin/render_readmes.rs +++ b/src/bin/crates-admin/render_readmes.rs @@ -19,6 +19,7 @@ use flate2::read::GzDecoder; use reqwest::{blocking::Client, header}; use std::str::FromStr; use tar::{self, Archive}; +use tokio::runtime::Handle; const USER_AGENT: &str = "crates-admin"; @@ -121,17 +122,13 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> { println!("[{}-{}] Rendering README...", krate_name, version.num); let readme = get_readme(&storage, &client, &version, &krate_name)?; if !readme.is_empty() { - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .context("Failed to initialize tokio runtime")?; - - rt.block_on(storage.upload_readme( - &krate_name, - &version.num, - readme.into(), - )) - .context("Failed to upload rendered README file to S3")?; + Handle::current() + .block_on(storage.upload_readme( + &krate_name, + &version.num, + readme.into(), + )) + .context("Failed to upload rendered README file to S3")?; } Ok(())