apt_swarm/p2p/
update_check.rs1use crate::args::ContainerUpdateCheck;
2use crate::errors::*;
3use crate::p2p;
4use crate::plumbing::update;
5use std::convert::Infallible;
6use tokio::time;
7
8pub async fn spawn_update_check(image: String, commit: String) -> Result<Infallible> {
9 let mut interval = time::interval(p2p::UPDATE_CHECK_INTERVAL);
10 debug!("Delaying first update check");
11 time::sleep(p2p::UPDATE_CHECK_DEBOUNCE).await;
12 let check = ContainerUpdateCheck { image, commit };
13 loop {
14 interval.tick().await;
15 match update::check(&check).await {
16 Ok(update::Updates::Available { current, latest }) => {
17 warn!(
18 "We're running an outdated version of {:?}, going to shutdown in some minutes... (current={:?}, latest={:?})",
19 check.image, current, latest
20 );
21 time::sleep(p2p::UPDATE_SHUTDOWN_DELAY).await;
22 bail!("Sending shutdown signal to request container image update");
23 }
24 Ok(_) => (),
25 Err(err) => {
26 warn!("Update check failed: {err:#}");
27 }
28 }
29 }
30}