ALPHA: wire is a tool to deploy nixos systems wire.althaea.zone/
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at stable 58 lines 1.5 kB view raw
1// SPDX-License-Identifier: AGPL-3.0-or-later 2// Copyright 2024-2025 wire Contributors 3 4use std::fmt::Display; 5 6use tracing::{Level, event, instrument}; 7 8use crate::{ 9 HiveLibError, 10 hive::node::{Context, ExecuteStep, SharedTarget}, 11}; 12 13#[derive(Debug)] 14#[cfg_attr(test, derive(PartialEq))] 15pub struct Ping { 16 pub target: SharedTarget, 17} 18 19impl Display for Ping { 20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 21 write!(f, "Ping node") 22 } 23} 24 25impl ExecuteStep for Ping { 26 #[instrument(skip_all, name = "ping")] 27 async fn execute(&self, ctx: &mut Context) -> Result<(), HiveLibError> { 28 loop { 29 let target = self.target.0.read().await; 30 31 event!( 32 Level::INFO, 33 status = "attempting", 34 host = target.get_preferred_host()?.to_string() 35 ); 36 37 if target.ping(ctx.modifiers).await.is_ok() { 38 event!( 39 Level::INFO, 40 status = "success", 41 host = target.get_preferred_host()?.to_string() 42 ); 43 return Ok(()); 44 } 45 46 // ? will take us out if we ran out of hosts 47 event!( 48 Level::WARN, 49 status = "failed to ping", 50 host = target.get_preferred_host()?.to_string() 51 ); 52 53 drop(target); 54 55 self.target.0.write().await.host_failed(); 56 } 57 } 58}