-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add health check service with HTTP port configuration and update depe…
…ndencies (#6) * Add health check service with HTTP port configuration and update dependencies * fix ci
- Loading branch information
Showing
8 changed files
with
167 additions
and
30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
application: | ||
host: 0.0.0.0 | ||
grpc_port: 8080 | ||
grpc_port: 8080 | ||
http_port: 8081 |
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,42 @@ | ||
use crate::configuration::Settings; | ||
use axum::{routing::get, Router}; | ||
use tokio::net::TcpListener; | ||
|
||
async fn health_check_handler() -> &'static str { | ||
"healthy" | ||
} | ||
|
||
pub struct HealthService { | ||
port: u16, | ||
server: axum::serve::Serve<TcpListener, Router, Router>, | ||
} | ||
|
||
impl HealthService { | ||
pub async fn build(settings: Settings) -> anyhow::Result<Self> { | ||
let address = format!( | ||
"{}:{}", | ||
settings.application.host, settings.application.http_port | ||
); | ||
let listener = TcpListener::bind(address).await?; | ||
let addr = listener.local_addr()?; | ||
|
||
let app = Router::new().route("/", get(health_check_handler)); | ||
|
||
// Build the server | ||
let server = axum::serve(listener, app); | ||
Ok(HealthService { | ||
port: addr.port(), | ||
server, | ||
}) | ||
} | ||
|
||
pub fn port(&self) -> u16 { | ||
self.port | ||
} | ||
|
||
pub async fn run(self) -> anyhow::Result<()> { | ||
tracing::info!("Health check server running on port {}", self.port); | ||
self.server.await?; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod configuration; | ||
pub mod health_check; | ||
pub mod protobuf; | ||
pub mod queue; | ||
pub mod service; | ||
|
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