diff --git a/src/main.rs b/src/main.rs index 222cb29..ea85a8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,38 +115,44 @@ async fn filter_task( } } -async fn log_task(mut rx: mpsc::Receiver) { - println!("log start"); +async fn restart_task(connection: Arc, mut rx: mpsc::Receiver) { + println!("restart task start"); while let Some(containers) = rx.recv().await { - println!("log -> found: {}", containers.len()); + println!("restart -> found: {}", containers.len()); for container_id in containers { - println!("log -> container: {}", container_id); + print!("restart -> container: {}...", &container_id); + let res = restart_container(&connection, container_id.as_str()).await; + match res { + Ok(_) => println!("ok\n"), + Err(e) => println!("error: \n{e:?}\n") + } } - println!("") } } #[tokio::main] async fn main() -> anyhow::Result<()> { let connection = Arc::new(Docker::connect_with_defaults()?); + let query_connection = connection.clone(); + let restart_connection = connection.clone(); let (shutdown_tx, shutdown_rx) = mpsc::channel::<()>(1); let (query_tx, filter_rx) = mpsc::channel::(1); - let (filter_tx, log_rx) = mpsc::channel::(1); + let (filter_tx, restart_rx) = mpsc::channel::(1); let interval = Duration::from_secs(10); let unhealthy_timeout = Duration::from_secs(35); tokio::try_join!( tokio::spawn(query_task( - connection.clone(), + query_connection, interval, query_tx, shutdown_rx )), tokio::spawn(filter_task(unhealthy_timeout, filter_rx, filter_tx)), - tokio::spawn(log_task(log_rx)), + tokio::spawn(restart_task(restart_connection, restart_rx)), tokio::spawn(async { println!("shutdown -> sleep"); tokio::time::sleep(Duration::from_secs(80)).await;