Skip to content

Commit be88d81

Browse files
authored
Merge pull request #2226 from Archisman-Mridha/fix/2109
Provide feedback if it takes a while to download a remote component on `spin up`
2 parents bbbb59b + d17ecb7 commit be88d81

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/loader/src/local.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use anyhow::{bail, ensure, Context, Result};
44
use futures::future::try_join_all;
55
use reqwest::Url;
6-
use spin_common::{paths::parent_dir, ui::quoted_path};
6+
use spin_common::{paths::parent_dir, sloth, ui::quoted_path};
77
use spin_locked_app::{
88
locked::{
99
self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentSource,
@@ -94,6 +94,8 @@ impl LocalLoader {
9494
})
9595
.collect::<Result<Vec<_>>>()?;
9696

97+
let sloth_guard = warn_if_component_load_slothful();
98+
9799
// Load all components concurrently
98100
let components = try_join_all(components.into_iter().map(|(id, c)| async move {
99101
self.load_component(&id, c)
@@ -102,6 +104,8 @@ impl LocalLoader {
102104
}))
103105
.await?;
104106

107+
drop(sloth_guard);
108+
105109
Ok(LockedApp {
106110
spin_lock_version: Default::default(),
107111
metadata,
@@ -516,3 +520,10 @@ fn file_url(path: impl AsRef<Path>) -> Result<String> {
516520
.with_context(|| format!("Couldn't resolve `{}`", path.display()))?;
517521
Ok(Url::from_file_path(abs_path).unwrap().to_string())
518522
}
523+
524+
const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;
525+
526+
fn warn_if_component_load_slothful() -> sloth::SlothGuard {
527+
let message = "Loading Wasm components is taking a few seconds...";
528+
sloth::warn_if_slothful(SLOTH_WARNING_DELAY_MILLIS, format!("{message}\n"))
529+
}

0 commit comments

Comments
 (0)