diff --git a/src/config.rs b/src/config.rs index 468b68a..a401746 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,8 +22,10 @@ pub struct Config { pub triggers: HashMap, #[serde(default = "default_min_restart_interval")] pub min_restart_interval_seconds: u64, - #[serde()] + #[serde(default = "default_restart")] pub restart: bool, + #[serde(default = "default_fallback_to_cache")] + pub fallback_to_cache: bool, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] @@ -58,6 +60,7 @@ impl Default for Config { }, min_restart_interval_seconds: default_min_restart_interval(), restart: default_restart(), + fallback_to_cache: default_fallback_to_cache() } } } @@ -70,6 +73,10 @@ fn default_restart() -> bool { true } +fn default_fallback_to_cache() -> bool { + true +} + pub async fn load(path: P) -> T where P: AsRef, diff --git a/src/main.rs b/src/main.rs index 5ef4570..a44413b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ pub async fn main() { }; let destinations: Vec = - prepare_destinations(&ctx, destinations.destinations).await; + prepare_destinations(&ctx, destinations.destinations, config.fallback_to_cache).await; let changed_sources: Vec<_> = destinations .iter() @@ -153,13 +153,14 @@ pub async fn main() { async fn prepare_destinations( ctx: &Context, destinations: HashMap, + fallback_to_cache: bool ) -> Vec { let mut futures = Vec::new(); for (destination_name, destination) in destinations { let ctx = ctx.clone(); let future = tokio::spawn(async move { - prepare_destination(&ctx, &destination_name, &destination) + prepare_destination(&ctx, &destination_name, &destination, fallback_to_cache) .await .expect(&format!( "failed to prepare destination '{}'", @@ -177,6 +178,8 @@ async fn prepare_destination( ctx: &Context, destination_name: &str, destination: &config::Destination, + fallback_to_cache: bool + ) -> Result { let cache_root = Path::new(CACHE_ROOT).join(destination_name); @@ -190,9 +193,20 @@ async fn prepare_destination( match source::load(ctx, cache_entry, source, &source_set.transform).await { Ok(reference) => cache_files.push((key.clone(), reference)), Err(err) => { - eprintln!("failed to load {}: {:?}! excluding.", key, err); - ctx.status - .write(format!("Failed to load {}... Excluding!", key)); + match if fallback_to_cache { cache.entry(key.clone()).get_existing() } else { None } { + Some(reference) => { + eprintln!("failed to load {}: {:?}! Loading from cache.", key, err); + ctx.status + .write(format!("Failed to load {}... Loading from cache!", key)); + cache_files.push((key.clone(), reference)) + } + None => { + eprintln!("failed to load {}: {:?}! excluding.", key, err); + ctx.status + .write(format!("Failed to load {}... Excluding!", key)); + } + } + } } }