diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 3249fcb1..91717d04 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -48,7 +48,6 @@ //! [`action_redirections`]: Config#structfield.action_redirections use bytes::BytesMut; -use flume::RecvError; use futures_util::StreamExt; use log::{error, info, warn}; use reqwest::{Certificate, Client, ClientBuilder, Identity, Response}; @@ -78,8 +77,6 @@ pub enum Error { Reqwest(#[from] reqwest::Error), #[error("File io Error: {0}")] Io(#[from] std::io::Error), - #[error("Error receiving action: {0}")] - Recv(#[from] RecvError), #[error("Empty file name")] EmptyFileName, #[error("Missing file path")] @@ -139,15 +136,23 @@ impl FileDownloader { /// Spawn a thread to handle downloading files as notified by download actions and for forwarding the updated actions /// back to bridge for further processing, e.g. OTA update installation. #[tokio::main(flavor = "current_thread")] - pub async fn start(mut self) -> Result<(), Error> { + pub async fn start(mut self) { let routes = &self.config.actions; let download_rx = match self.bridge_tx.register_action_routes(routes).await { Some(r) => r, - _ => return Ok(()), + _ => return, }; + + info!("Downloader thread is ready to receive download actions"); loop { self.sequence = 0; - let action = download_rx.recv_async().await?; + let action = match download_rx.recv_async().await { + Ok(a) => a, + Err(e) => { + error!("Downloader thread had to stop: {e}"); + break; + } + }; self.action_id = action.action_id.clone(); let duration = match self.timeouts.get(&action.name) { @@ -382,7 +387,7 @@ mod test { let downloader = FileDownloader::new(Arc::new(config), bridge_tx).unwrap(); // Start FileDownloader in separate thread - std::thread::spawn(|| downloader.start().unwrap()); + std::thread::spawn(|| downloader.start()); // Create a firmware update action let download_update = DownloadFile { @@ -458,7 +463,7 @@ mod test { let downloader = FileDownloader::new(Arc::new(config), bridge_tx).unwrap(); // Start FileDownloader in separate thread - std::thread::spawn(|| downloader.start().unwrap()); + std::thread::spawn(|| downloader.start()); // Create a firmware update action let download_update = DownloadFile {