-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into lemmih/mpool-push-untrusted
- Loading branch information
Showing
18 changed files
with
269 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use std::{ | ||
io::{stdout, Write}, | ||
time::Duration, | ||
}; | ||
|
||
use crate::health::DEFAULT_HEALTHCHECK_PORT; | ||
use crate::rpc; | ||
use clap::Subcommand; | ||
use http::StatusCode; | ||
use ticker::Ticker; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum HealthcheckCommand { | ||
/// Display ready status | ||
Ready { | ||
/// Don't exit until node is ready | ||
#[arg(long)] | ||
wait: bool, | ||
/// Healthcheck port | ||
#[arg(long, default_value_t=DEFAULT_HEALTHCHECK_PORT)] | ||
healthcheck_port: u16, | ||
}, | ||
} | ||
|
||
impl HealthcheckCommand { | ||
pub async fn run(self, client: rpc::Client) -> anyhow::Result<()> { | ||
match self { | ||
Self::Ready { | ||
wait, | ||
healthcheck_port, | ||
} => { | ||
let ticker = Ticker::new(0.., Duration::from_secs(1)); | ||
let mut stdout = stdout(); | ||
|
||
let url = format!( | ||
"http://{}:{}/readyz?verbose", | ||
client.base_url().host_str().unwrap_or("localhost"), | ||
healthcheck_port, | ||
); | ||
|
||
for _ in ticker { | ||
let response = reqwest::get(&url).await?; | ||
let status = response.status(); | ||
let text = response.text().await?; | ||
|
||
println!("{}", text); | ||
|
||
if !wait { | ||
break; | ||
} | ||
if status == StatusCode::OK { | ||
println!("Done!"); | ||
break; | ||
} | ||
|
||
for _ in 0..(text.matches('\n').count() + 1) { | ||
write!( | ||
stdout, | ||
"\r{}{}", | ||
anes::MoveCursorUp(1), | ||
anes::ClearLine::All, | ||
)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.