diff --git a/torrential/src/download.rs b/torrential/src/download.rs index 21827cb1..d65b545f 100644 --- a/torrential/src/download.rs +++ b/torrential/src/download.rs @@ -29,7 +29,7 @@ pub async fn create_download_context<'a>( let backend = backend()?; let mut chunk_lookup_table = - HashMap::with_capacity(context.manifest.values().map(|v| v.ids.len()).sum()); + HashMap::with_capacity_and_hasher(context.manifest.values().map(|v| v.ids.len()).sum(), Default::default()); for (path, file_chunks) in context.manifest { let mut start = 0; diff --git a/torrential/src/main.rs b/torrential/src/main.rs index 2e989045..3a9ae247 100644 --- a/torrential/src/main.rs +++ b/torrential/src/main.rs @@ -17,7 +17,7 @@ use axum::{ response::{AppendHeaders, IntoResponse}, routing::{get, post}, }; -use log::{error, info, warn}; +use log::{error, info}; use serde::Deserialize; use tokio::sync::{OnceCell, Semaphore}; @@ -71,11 +71,8 @@ async fn serve_file( } else { info!("generating context..."); let context_result = - create_download_context(init_data, game_id.clone(), version_name.clone()).await; - info!("cleaned up semaphore"); - - let new_context = context_result.inspect_err(|v| warn!("{:?}", v))?; - state.context_cache.insert(key.clone(), new_context); + create_download_context(init_data, game_id.clone(), version_name.clone()).await?; + state.context_cache.insert(key.clone(), context_result); info!("continuing download"); @@ -125,6 +122,14 @@ struct TokenPayload { token: String, } +async fn healthcheck(State(state): State>>) -> StatusCode { + let inited = state.token.initialized(); + if !inited { + return StatusCode::SERVICE_UNAVAILABLE; + } + return StatusCode::OK; +} + async fn set_token( State(state): State>>, Json(payload): Json, @@ -205,6 +210,7 @@ async fn main() { get(serve_file), ) .route("/token", post(set_token)) + .route("/healthcheck", get(healthcheck)) .with_state(shared_state); // run our app with hyper, listening globally on port 3000