From 5a15f07872584e58be73899727d6a08a75138ca2 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 27 Jul 2023 16:43:09 +0200 Subject: [PATCH] Include builtins in origin syncing --- src/domain/manager.rs | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/domain/manager.rs b/src/domain/manager.rs index 7563a04..1ac1d56 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -211,24 +211,39 @@ impl ManagerImpl { manager } + async fn sync_origins_once(&self) { + match self.domain_store.all_domains() { + Ok(domains) => domains, + Err(err) => { + log::error!("Error fetching all domains: {err}"); + return; + } + } + .into_iter() + .for_each(|domain| { + log::info!("Syncing domain {}", &domain); + + let settings = match self.domain_store.get(&domain) { + Ok(settings) => settings, + Err(err) => { + log::error!("Error syncing {domain}: {err}"); + return; + } + }; + + let descr = &settings.settings.origin_descr; + + if let Err(err) = self.origin_store.sync(descr) { + log::error!("Failed to sync origin for {domain}, origin:{descr:?}: {err}") + } + }); + } + async fn sync_origins(&self, canceller: CancellationToken) { let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(20 * 60)); loop { tokio::select! { - _ = interval.tick() => { - match self.origin_store.all_descrs() { - Ok(iter) => iter.into_iter(), - Err(err) => { - log::error!("Error fetching origin descriptors: {err}"); - return; - } - } - .for_each(|descr| { - if let Err(err) = self.origin_store.sync(&descr) { - log::error!("Failed to sync store for {:?}: {err}", descr) - } - }); - }, + _ = interval.tick() => self.sync_origins_once().await, _ = canceller.cancelled() => return, } }