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

View File

@@ -0,0 +1,15 @@
[package]
name = "churn-agent"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true
dotenv.workspace = true
axum.workspace = true

View File

@@ -0,0 +1,58 @@
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 {
Daemon {
#[arg(env = "CHURN_ADDR", long)]
host: SocketAddr,
},
Connect {
/// agent name is the hostname which other agents or servers can resolve and connect via. It should be unique
#[arg(env = "CHURN_AGENT_NAME", long)]
agent_name: String,
#[arg(env = "CHURN_ADDR", long)]
host: SocketAddr,
#[arg(env = "CHURN_TOKEN", long)]
token: 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<()> {
match cmd.command {
Some(Commands::Daemon { host }) => {
tracing::info!("starting agent server on {}", host);
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
Ok(())
}
Some(Commands::Connect {
host,
token,
agent_name,
}) => todo!(),
None => todo!(),
}
}