Skip to content

Start axum migration #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 19, 2022
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
106 changes: 106 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ consistency_check = ["crates-index", "rayon"]
sentry = "0.27.0"
sentry-panic = "0.27.0"
sentry-tracing = "0.27.0"
sentry-tower = { version = "0.27.0", features = ["http"] }
sentry-anyhow = { version = "0.27.0", features = ["backtrace"] }
log = "0.4"
tracing = "0.1.37"
Expand Down Expand Up @@ -89,6 +90,14 @@ memmap2 = "0.5.0"
iron = "0.6"
router = "0.6"

# axum dependencies
axum = "0.5.17"
hyper = { version = "0.14.15", default-features = false }
tower = "0.4.11"
tower-service = "0.3.2"
tower-http = { version = "0.3.4", features = ["trace"] }
mime = "0.3.16"

# NOTE: if you change this, also double-check that the comment in `queue_builder::remove_tempdirs` is still accurate.
tempfile = "3.1.0"

Expand Down
16 changes: 11 additions & 5 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use docs_rs::utils::{
get_config, queue_builder, remove_crate_priority, set_crate_priority, ConfigName,
};
use docs_rs::{
BuildQueue, Config, Context, Index, Metrics, PackageKind, RustwideBuilder, Server, Storage,
start_web_server, BuildQueue, Config, Context, Index, Metrics, PackageKind, RustwideBuilder,
Storage,
};
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
use tokio::runtime::{Builder, Runtime};
use tracing_log::LogTracer;
use tracing_subscriber::{filter::Directive, prelude::*, EnvFilter};

Expand Down Expand Up @@ -156,10 +157,10 @@ impl CommandLine {
}
Self::StartWebServer { socket_addr } => {
// Blocks indefinitely
let _ = Server::start(Some(&socket_addr), &ctx)?;
start_web_server(Some(&socket_addr), &ctx)?;
}
Self::Daemon { registry_watcher } => {
docs_rs::utils::start_daemon(&ctx, registry_watcher == Toggle::Enabled)?;
docs_rs::utils::start_daemon(ctx, registry_watcher == Toggle::Enabled)?;
}
Self::Database { subcommand } => subcommand.handle_args(ctx)?,
Self::Queue { subcommand } => subcommand.handle_args(ctx)?,
Expand Down Expand Up @@ -536,6 +537,7 @@ enum DeleteSubcommand {
},
}

#[derive(Clone)]
struct BinContext {
build_queue: OnceCell<Arc<BuildQueue>>,
storage: OnceCell<Arc<Storage>>,
Expand Down Expand Up @@ -597,7 +599,11 @@ impl Context for BinContext {
fn cdn(self) -> CdnBackend = CdnBackend::new(&self.config()?, &self.runtime()?);
fn config(self) -> Config = Config::from_env()?;
fn metrics(self) -> Metrics = Metrics::new()?;
fn runtime(self) -> Runtime = Runtime::new()?;
fn runtime(self) -> Runtime = {
Builder::new_multi_thread()
.enable_all()
.build()?
};
fn index(self) -> Index = {
let config = self.config()?;
let path = config.registry_index_path.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{path::PathBuf, process::Command};

use anyhow::Context;
use crates_index_diff::git;
use tracing::debug;
use url::Url;

use self::api::Api;
Expand Down Expand Up @@ -90,6 +89,7 @@ impl Index {

#[cfg(feature = "consistency_check")]
pub(crate) fn crates(&self) -> Result<crates_index::Index> {
use tracing::debug;
// First ensure the index is up to date, peeking will pull the latest changes without
// affecting anything else.
debug!("Updating index");
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use self::docbuilder::RustwideBuilder;
pub use self::index::Index;
pub use self::metrics::Metrics;
pub use self::storage::Storage;
pub use self::web::Server;
pub use self::web::start_web_server;

mod build_queue;
pub mod cdn;
Expand Down
Loading