Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
enhancement: forc index status formatting update (#1365)
Browse files Browse the repository at this point in the history
forc index status formatting update
  • Loading branch information
lostman authored Sep 20, 2023
1 parent 887ab38 commit 14b307c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/forc-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fuel-indexer-lib = { workspace = true }
fuel-tx = { features = ["builder"], workspace = true }
fuels = { default-features = false, workspace = true }
hex = "0.4.3"
humantime = "2.1.0"
hyper-rustls = { version = "0.23", features = ["http2"] }
indicatif = "0.17"
owo-colors = "1.3.0"
Expand Down
32 changes: 26 additions & 6 deletions plugins/forc-index/src/ops/forc_index_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,34 @@ pub async fn status(
return Ok(());
}

let res_json = res
let result = res
.json::<Map<String, Value>>()
.await
.expect("Failed to read JSON response.");

info!(
"\n✅ Sucessfully fetched service health:\n\n{}",
to_string_pretty(&res_json).unwrap()
);
info!("\n✅ Successfully fetched service health:\n");

let client_status = result
.get("client_status")
.and_then(|x| x.as_str())
.unwrap_or("missing");
let database_status = result
.get("database_status")
.and_then(|x| x.as_str())
.unwrap_or("missing");
let uptime = result
.get("uptime")
.and_then(|x| x.as_str())
.and_then(|x| x.to_string().parse::<u64>().ok())
.map(|x| {
humantime::format_duration(std::time::Duration::from_secs(x))
.to_string()
})
.unwrap_or("missing".to_string());

info!("client status: {client_status}");
info!("database status: {database_status}");
info!("uptime: {uptime}\n");
}
Err(e) => {
error!("\n❌ Could not connect to indexer service:\n'{e}'");
Expand Down Expand Up @@ -70,6 +89,7 @@ pub async fn status(
.await
.expect("Failed to read JSON response.");

info!("indexers:");
print_indexers(result);
}
Err(e) => {
Expand Down Expand Up @@ -121,7 +141,7 @@ fn print_indexers(indexers: Vec<RegisteredIndexer>) {
};
println!("{} {} {}", ng2, ig1, indexer.identifier);
println!("{} {} • id: {}", ng2, ig2, indexer.id);
println!("{} {} • created_at: {}", ng2, ig2, indexer.created_at);
println!("{} {} • created at: {}", ng2, ig2, indexer.created_at);
println!("{} {} • pubkey: {:?}", ng2, ig2, indexer.pubkey);
}
if !is_last_namespace {
Expand Down

0 comments on commit 14b307c

Please sign in to comment.