Skip to content

Commit bd2f5d4

Browse files
committed
chore: try one more time
1 parent acfb85c commit bd2f5d4

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

Diff for: Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ RUN --mount=type=cache,target=/app/target \
5454
FROM scratch
5555

5656
# Copy compiled application
57-
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/klickhouse_example /klickhouse_example
57+
COPY --from=builder /app/klickhouse_example /klickhouse_example
5858
# Copy application config
5959
COPY ./confik.toml .
6060

Diff for: aarch64.Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ RUN --mount=type=cache,target=/app/target \
5353
FROM scratch
5454

5555
# copy compiled application
56-
COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/klickhouse_example /klickhouse_example
56+
COPY --from=builder /app/klickhouse_example /klickhouse_example
57+
# Copy application config
58+
COPY ./confik.toml .
5759

5860
# specify that the application is started as PID 1
5961
ENTRYPOINT ["/klickhouse_example"]

Diff for: src/web/app_state.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ impl AppState {
3232
.await
3333
.map_err(|e| eyre!("Failed to connect to Clickhouse: {}", e))?;
3434

35+
pool.check_pool().await?;
36+
3537
Ok(pool)
3638
}
3739

40+
pub async fn check_clickhouse_connection(&self) -> Result<()> {
41+
self.clickhouse_pool.check_pool().await
42+
}
43+
3844
pub fn config(&self) -> &AppConfig {
3945
&self.config
4046
}

Diff for: src/web/global_panic_handler.rs

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub fn setup_global_panic_handler(app_state: Data<AppState>) {
1616
.map(ToString::to_string)
1717
.unwrap_or_else(|| "Unknown panic".to_string());
1818

19-
println!("Global panic handler called #2");
20-
2119
tokio::task::spawn(async move {
2220
// Create log
2321
let log = WebServerLog {
@@ -32,8 +30,6 @@ pub fn setup_global_panic_handler(app_state: Data<AppState>) {
3230
response_time: 0.0,
3331
};
3432

35-
println!("Global panic handler called #3");
36-
3733
// Write log to Clickhouse
3834
if let Err(e) = app_state.ch_logger().log(log).await {
3935
eprintln!("Failed to log panic to ClickHouse: {:?}", e);

Diff for: src/web/handlers/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use actix_web::{get, HttpResponse, Responder};
1+
use crate::web::app_state::AppState;
2+
use actix_web::{get, web, HttpResponse, Responder};
23
use tracing_actix_web::RequestId;
34

45
#[get("/")]
56
pub async fn index(request_id: RequestId) -> impl Responder {
67
format!("request_id: {}", request_id)
78
}
89

9-
#[get("/health")]
10-
pub async fn health() -> impl Responder {
11-
"I'm alive!"
12-
}
13-
1410
#[get("/fail")]
1511
#[allow(clippy::unnecessary_literal_unwrap)]
1612
pub async fn fail_endpoint() -> impl Responder {
@@ -19,3 +15,11 @@ pub async fn fail_endpoint() -> impl Responder {
1915
let value = result.unwrap();
2016
HttpResponse::Ok().body(format!("Value: {}", value))
2117
}
18+
19+
#[get("/health")]
20+
pub async fn health(app_state: web::Data<AppState>) -> impl Responder {
21+
match app_state.check_clickhouse_connection().await {
22+
Ok(_) => HttpResponse::Ok().body("I'm alive!"),
23+
Err(e) => HttpResponse::InternalServerError().body(format!("Error: {}", e)),
24+
}
25+
}

Diff for: src/web/startup.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ use crate::web::global_panic_handler::setup_global_panic_handler;
1313
use crate::web::handlers::{fail_endpoint, health, index};
1414

1515
pub async fn run_serve(config: AppConfig) -> Result<actix_web::dev::Server> {
16-
let app_state = web::Data::new(AppState::build(config).await?);
17-
setup_global_panic_handler(app_state.clone());
16+
let app_state = AppState::build(config).await?;
17+
let data_app_state = web::Data::new(app_state.clone());
18+
setup_global_panic_handler(data_app_state.clone());
1819

1920
let port = app_state.config().http_port;
2021
let addr = format!("0.0.0.0:{}", port);
2122

2223
let server = HttpServer::new(move || {
2324
App::new()
24-
.app_data(app_state.clone())
25+
.app_data(data_app_state.clone())
2526
.wrap(TracingLogger::default())
2627
.wrap(NormalizePath::new(
2728
actix_web::middleware::TrailingSlash::Trim,

0 commit comments

Comments
 (0)