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

Method run

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

Source from the content-addressed store, hash-verified

356 }
357
358 pub async fn run(&mut self) {
359 if let Err(err) = self.init().await {
360 error!("Encountered error during init: {}", err);
361 return;
362 }
363
364 async fn shutdown_signal() {
365 futures_util::future::select(
366 tokio::signal::ctrl_c().map(|_| ()).boxed(),
367 #[cfg(unix)]
368 tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
369 .unwrap()
370 .recv()
371 .map(|_| ())
372 .boxed(),
373 #[cfg(not(unix))]
374 futures_util::future::pending::<()>(),
375 )
376 .await;
377 }
378
379 loop {
380 if let Err(err) = self.do_sync().await {
381 warn!("Encountered error during sync: {}", err);
382 }
383
384 match futures_util::future::select(
385 tokio::time::sleep(Duration::from_secs_f64(self.app_state.config.sync_interval))
386 .boxed(),
387 shutdown_signal().boxed(),
388 )
389 .await
390 {
391 futures_util::future::Either::Left(_) => {}
392 futures_util::future::Either::Right(_) => break,
393 }
394 }
395
396 log::info!("Shutting down...");
397 for source in &mut self.sources {
398 _ = source.shutdown().await.log_error(std::module_path!(), |e| {
399 format!("Failed to gracefully shutdown source: {}", e)
400 });
401 }
402 }
403}

Callers 2

mainFunction · 0.80
initMethod · 0.80

Calls 4

do_syncMethod · 0.80
log_errorMethod · 0.80
initMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected