MCPcopy Create free account
hub / github.com/BigBoot/AutoKuma / do_sync

Method do_sync

autokuma/src/sync.rs:217–348  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

215 }
216
217 async fn do_sync(&mut self) -> Result<()> {
218 let kuma = self.get_connection().await?;
219
220 crate::migrations::migrate(&self.app_state, &kuma).await?;
221
222 self.app_state.db.clean(
223 &kuma
224 .get_monitors()
225 .await?
226 .into_iter()
227 .filter_map(|(_, monitor)| monitor.common().id().clone())
228 .collect::<HashSet<_>>(),
229 &kuma
230 .get_notifications()
231 .await?
232 .into_iter()
233 .filter_map(|notification| notification.id)
234 .collect::<HashSet<_>>(),
235 &kuma
236 .get_docker_hosts()
237 .await?
238 .into_iter()
239 .filter_map(|docker_host| docker_host.id)
240 .collect::<HashSet<_>>(),
241 &kuma
242 .get_tags()
243 .await?
244 .into_iter()
245 .filter_map(|tag| tag.tag_id)
246 .collect::<HashSet<_>>(),
247 &kuma
248 .get_status_pages()
249 .await?
250 .into_iter()
251 .filter_map(|(_, status_page)| status_page.slug)
252 .collect::<HashSet<_>>(),
253 )?;
254
255 if let Some(auth_token) = kuma.get_auth_token().await {
256 self.auth_token = Some(auth_token);
257 }
258
259 let current_entities = get_managed_entities(&self.app_state, &kuma).await?;
260
261 let mut new_entities: HashMap<String, Entity> = HashMap::new();
262
263 for source in &mut self.sources {
264 trace!("Querying source: {}", source.name());
265 let entities = source.get_entities().await?;
266 trace!("Got {} entities from source", entities.len());
267 new_entities.extend(entities);
268 }
269
270 let to_delete = current_entities
271 .iter()
272 .filter(|(id, _)| !new_entities.contains_key(*id))
273 .collect_vec();
274

Callers 1

runMethod · 0.80

Calls 15

migrateFunction · 0.85
get_managed_entitiesFunction · 0.85
get_connectionMethod · 0.80
cleanMethod · 0.80
get_auth_tokenMethod · 0.80
iterMethod · 0.80
log_warnMethod · 0.80
create_entityMethod · 0.80
update_entityMethod · 0.80
flattenMethod · 0.80
request_to_deleteMethod · 0.80

Tested by

no test coverage detected