From da09b82b72c38e36aee499da65d750f62deb6e48 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 14 Jun 2020 15:03:31 +0200 Subject: [PATCH] Add some logic so force downloading will "restart" the downloader. --- source/downloader/mod.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source/downloader/mod.rs b/source/downloader/mod.rs index 23f2212..900f6eb 100644 --- a/source/downloader/mod.rs +++ b/source/downloader/mod.rs @@ -108,18 +108,34 @@ pub fn download_and_save_feeds( } if let Some(receiver) = receiver { - match receiver.try_recv() { + let instruction = match receiver.try_recv() { Ok(value) => { - println!( - "[DL] Received instruction {:?} while downloading, ignoring it.", - value, - ); + println!("[DL] Received instruction {:?} while downloading.", value,); + Some(value) } Err(err) => { if err != mpsc::TryRecvError::Empty { println!("[DL] Error attempting to receive from channel: {}", err); break; } + None + } + }; + + if let Some(instruction) = instruction { + // If we receive the force download all instruction and we're not already force downloading + // run this same function with force download all enabled. + if instruction == DownloaderInstruction::ForceDownloadAll + && !force_download + { + println!( + "[DL] Restarting the downloader with force download enabled." + ); + download_and_save_feeds(&conn, true, false, Some(&receiver)).unwrap(); + break; + } else { + // Otherwise just print that we're ignoring the instruction. + println!("[DL] Ignoring the {:?} instruction.", instruction); } } }