add restart task
This commit is contained in:
parent
f6d99b224e
commit
8fc3e5a855
22
src/main.rs
22
src/main.rs
@ -115,38 +115,44 @@ async fn filter_task(
|
||||
}
|
||||
}
|
||||
|
||||
async fn log_task(mut rx: mpsc::Receiver<Containers>) {
|
||||
println!("log start");
|
||||
async fn restart_task(connection: Arc<Docker>, mut rx: mpsc::Receiver<Containers>) {
|
||||
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::<Containers>(1);
|
||||
let (filter_tx, log_rx) = mpsc::channel::<Containers>(1);
|
||||
let (filter_tx, restart_rx) = mpsc::channel::<Containers>(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;
|
||||
|
Loading…
Reference in New Issue
Block a user