Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pub struct Config {
pub triggers: HashMap<String, Trigger>,
#[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)]
Expand Down Expand Up @@ -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()
}
}
}
Expand All @@ -70,6 +73,10 @@ fn default_restart() -> bool {
true
}

fn default_fallback_to_cache() -> bool {
true
}

pub async fn load<P, T>(path: P) -> T
where
P: AsRef<Path>,
Expand Down
24 changes: 19 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn main() {
};

let destinations: Vec<PreparedDestination> =
prepare_destinations(&ctx, destinations.destinations).await;
prepare_destinations(&ctx, destinations.destinations, config.fallback_to_cache).await;

let changed_sources: Vec<_> = destinations
.iter()
Expand Down Expand Up @@ -153,13 +153,14 @@ pub async fn main() {
async fn prepare_destinations(
ctx: &Context,
destinations: HashMap<String, config::Destination>,
fallback_to_cache: bool
) -> Vec<PreparedDestination> {
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 '{}'",
Expand All @@ -177,6 +178,8 @@ async fn prepare_destination(
ctx: &Context,
destination_name: &str,
destination: &config::Destination,
fallback_to_cache: bool

) -> Result<PreparedDestination> {
let cache_root = Path::new(CACHE_ROOT).join(destination_name);

Expand All @@ -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));
}
}

}
}
}
Expand Down
Loading