YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
chore: add retry to pipes download
Louis Beaumontd3937dd80e7a
diff --git a/screenpipe-core/src/pipes.rs b/screenpipe-core/src/pipes.rsindex de32f47d8..2ffd475dc 100644--- a/screenpipe-core/src/pipes.rs+++ b/screenpipe-core/src/pipes.rs@@ -253,6 +253,44 @@ mod pipes {Ok(())}+ // Add this helper function for retrying installations+ async fn retry_install(bun_path: &Path, dest_dir: &Path, max_retries: u32) -> Result<()> {+ let mut attempt = 0;+ let mut last_error = None;++ while attempt < max_retries {+ let mut install_child = Command::new(bun_path)+ .arg("i")+ .current_dir(dest_dir)+ .stdout(std::process::Stdio::piped())+ .stderr(std::process::Stdio::piped())+ .spawn()?;++ // Stream logs for npm install+ if let Ok(()) = stream_logs("bun install", &mut install_child).await {+ let status = install_child.wait().await?;+ if status.success() {+ return Ok(());+ }+ }++ attempt += 1;+ let delay = std::time::Duration::from_secs(2u64.pow(attempt)); // exponential backoff+ error!(+ "install attempt {} failed, retrying in {} seconds",+ attempt,+ delay.as_secs()+ );+ tokio::time::sleep(delay).await;+ last_error = Some(anyhow::anyhow!(+ "installation failed after {} attempts",+ attempt+ ));+ }++ Err(last_error.unwrap_or_else(|| anyhow::anyhow!("installation failed")))+ }+pub async fn download_pipe(source: &str, screenpipe_dir: PathBuf) -> anyhow::Result<PathBuf> {info!("Processing pipe from source: {}", source);@@ -369,16 +407,8 @@ mod pipes {let bun_path = find_bun_path().ok_or_else(|| anyhow::anyhow!("bun not found"))?;- // Make bun install mandatory for all package.json pipes- let mut install_child = Command::new(&bun_path)- .arg("i")- .current_dir(&dest_dir)- .stdout(std::process::Stdio::piped())- .stderr(std::process::Stdio::piped())- .spawn()?;-- // Stream logs for npm install- stream_logs("bun install", &mut install_child).await?;+ // Make bun install mandatory for all package.json pipes with retries+ retry_install(&bun_path, &dest_dir, 3).await?;if package_data["dependencies"].get("next").is_some() {info!("Detected Next.js project, setting up for production");@@ -652,7 +682,10 @@ mod pipes {}// Add this function to handle cron state persistence- pub async fn get_last_cron_execution(pipe_dir: &Path, path: &str) -> Result<Option<SystemTime>> {+ pub async fn get_last_cron_execution(+ pipe_dir: &Path,+ path: &str,+ ) -> Result<Option<SystemTime>> {let state_file = pipe_dir.join(".cron_state.json");if !state_file.exists() {