Skip to content

Commit 929a74b

Browse files
committed
start axum migration
1 parent 6685320 commit 929a74b

17 files changed

+1044
-156
lines changed

Cargo.lock

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ consistency_check = ["crates-index", "rayon"]
2222
sentry = "0.27.0"
2323
sentry-panic = "0.27.0"
2424
sentry-tracing = "0.27.0"
25+
sentry-tower = { version = "0.27.0", features = ["http"] }
2526
sentry-anyhow = { version = "0.27.0", features = ["backtrace"] }
2627
log = "0.4"
2728
tracing = "0.1.37"
@@ -88,6 +89,14 @@ memmap2 = "0.5.0"
8889
iron = "0.6"
8990
router = "0.6"
9091

92+
# axum dependencies
93+
axum = "0.5.17"
94+
hyper = { version = "0.14.15", default-features = false }
95+
tower = "0.4.11"
96+
tower-service = "0.3.2"
97+
tower-http = { version = "0.3.4", features = ["trace"] }
98+
mime = "0.3.16"
99+
91100
# NOTE: if you change this, also double-check that the comment in `queue_builder::remove_tempdirs` is still accurate.
92101
tempfile = "3.1.0"
93102

src/bin/cratesfyi.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use docs_rs::utils::{
1313
get_config, queue_builder, remove_crate_priority, set_crate_priority, ConfigName,
1414
};
1515
use docs_rs::{
16-
BuildQueue, Config, Context, Index, Metrics, PackageKind, RustwideBuilder, Server, Storage,
16+
start_web_server, BuildQueue, Config, Context, Index, Metrics, PackageKind, RustwideBuilder,
17+
Storage,
1718
};
1819
use once_cell::sync::OnceCell;
19-
use tokio::runtime::Runtime;
20+
use tokio::runtime::{Builder, Runtime};
2021
use tracing_log::LogTracer;
2122
use tracing_subscriber::{filter::Directive, prelude::*, EnvFilter};
2223

@@ -156,10 +157,10 @@ impl CommandLine {
156157
}
157158
Self::StartWebServer { socket_addr } => {
158159
// Blocks indefinitely
159-
let _ = Server::start(Some(&socket_addr), &ctx)?;
160+
start_web_server(Some(&socket_addr), &ctx)?;
160161
}
161162
Self::Daemon { registry_watcher } => {
162-
docs_rs::utils::start_daemon(&ctx, registry_watcher == Toggle::Enabled)?;
163+
docs_rs::utils::start_daemon(ctx, registry_watcher == Toggle::Enabled)?;
163164
}
164165
Self::Database { subcommand } => subcommand.handle_args(ctx)?,
165166
Self::Queue { subcommand } => subcommand.handle_args(ctx)?,
@@ -536,6 +537,7 @@ enum DeleteSubcommand {
536537
},
537538
}
538539

540+
#[derive(Clone)]
539541
struct BinContext {
540542
build_queue: OnceCell<Arc<BuildQueue>>,
541543
storage: OnceCell<Arc<Storage>>,
@@ -597,7 +599,11 @@ impl Context for BinContext {
597599
fn cdn(self) -> CdnBackend = CdnBackend::new(&self.config()?, &self.runtime()?);
598600
fn config(self) -> Config = Config::from_env()?;
599601
fn metrics(self) -> Metrics = Metrics::new()?;
600-
fn runtime(self) -> Runtime = Runtime::new()?;
602+
fn runtime(self) -> Runtime = {
603+
Builder::new_multi_thread()
604+
.enable_all()
605+
.build()?
606+
};
601607
fn index(self) -> Index = {
602608
let config = self.config()?;
603609
let path = config.registry_index_path.clone();

src/index/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{path::PathBuf, process::Command};
33

44
use anyhow::Context;
55
use crates_index_diff::git;
6-
use tracing::debug;
76
use url::Url;
87

98
use self::api::Api;
@@ -90,6 +89,7 @@ impl Index {
9089

9190
#[cfg(feature = "consistency_check")]
9291
pub(crate) fn crates(&self) -> Result<crates_index::Index> {
92+
use tracing::debug;
9393
// First ensure the index is up to date, peeking will pull the latest changes without
9494
// affecting anything else.
9595
debug!("Updating index");

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::docbuilder::RustwideBuilder;
1010
pub use self::index::Index;
1111
pub use self::metrics::Metrics;
1212
pub use self::storage::Storage;
13-
pub use self::web::Server;
13+
pub use self::web::start_web_server;
1414

1515
mod build_queue;
1616
pub mod cdn;

0 commit comments

Comments
 (0)