feat: add simple health check

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-24 17:22:45 +02:00
commit f61d0bbf12
13 changed files with 2363 additions and 0 deletions

1
crates/churn/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

13
crates/churn/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "churn"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true
dotenv.workspace = true
axum.workspace = true

63
crates/churn/src/main.rs Normal file
View File

@@ -0,0 +1,63 @@
use std::net::SocketAddr;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(author, version, about, long_about = None, subcommand_required = true)]
struct Command {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Bootstrap {
#[arg(env = "CHURN_AGENT", long)]
host: String,
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_SERVER_TOKEN", long)]
server_token: String,
},
Health {
#[arg(env = "CHURN_SERVER", long)]
server: String,
#[arg(env = "CHURN_AGENT", long)]
agent: String,
},
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
let cli = Command::parse();
handle_command(cli).await?;
Ok(())
}
async fn handle_command(cmd: Command) -> anyhow::Result<()> {
if let Some(cmd) = cmd.command {
match cmd {
Commands::Bootstrap {
host,
server,
server_token,
} => todo!(),
Commands::Health { server, agent } => {
tracing::info!("connecting to server: {}", server);
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
tracing::info!("connecting to agent: {}", agent);
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
Ok(())
}
}
} else {
panic!("no command supplied")
}
}