Skip to content

Commit

Permalink
Merge pull request #2226 from Archisman-Mridha/fix/2109
Browse files Browse the repository at this point in the history
Provide feedback if it takes a while to download a remote component on `spin up`
  • Loading branch information
itowlson authored Jan 18, 2024
2 parents bbbb59b + d17ecb7 commit be88d81
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use anyhow::{bail, ensure, Context, Result};
use futures::future::try_join_all;
use reqwest::Url;
use spin_common::{paths::parent_dir, ui::quoted_path};
use spin_common::{paths::parent_dir, sloth, ui::quoted_path};
use spin_locked_app::{
locked::{
self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentSource,
Expand Down Expand Up @@ -94,6 +94,8 @@ impl LocalLoader {
})
.collect::<Result<Vec<_>>>()?;

let sloth_guard = warn_if_component_load_slothful();

// Load all components concurrently
let components = try_join_all(components.into_iter().map(|(id, c)| async move {
self.load_component(&id, c)
Expand All @@ -102,6 +104,8 @@ impl LocalLoader {
}))
.await?;

drop(sloth_guard);

Ok(LockedApp {
spin_lock_version: Default::default(),
metadata,
Expand Down Expand Up @@ -516,3 +520,10 @@ fn file_url(path: impl AsRef<Path>) -> Result<String> {
.with_context(|| format!("Couldn't resolve `{}`", path.display()))?;
Ok(Url::from_file_path(abs_path).unwrap().to_string())
}

const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;

fn warn_if_component_load_slothful() -> sloth::SlothGuard {
let message = "Loading Wasm components is taking a few seconds...";
sloth::warn_if_slothful(SLOTH_WARNING_DELAY_MILLIS, format!("{message}\n"))
}

0 comments on commit be88d81

Please sign in to comment.