From 6b1b343e284e2691b1db737d68cda07871fc3563 Mon Sep 17 00:00:00 2001 From: Mats Larsen Date: Mon, 1 Apr 2024 19:50:57 +0200 Subject: [PATCH] Address review comments --- README.md | 3 +++ src/healthcheck.rs | 10 +++------- src/main.rs | 8 ++++---- src/slack.rs | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1e1cf49..e1a23d7 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ cargo run # Docker docker build -t pizzapicker:latest . docker run -e SLACK_APP_TOKEN= pizzapicker:latest + +docker tag pizzapicker:latest .dkr.ecr.eu-north-1.amazonaws.com/pizzapicker-prod:latest +docker push .dkr.ecr.eu-north-1.amazonaws.com/pizzapicker-prod:latest ``` ## License diff --git a/src/healthcheck.rs b/src/healthcheck.rs index 9fa0fdf..3c5d4db 100644 --- a/src/healthcheck.rs +++ b/src/healthcheck.rs @@ -1,10 +1,9 @@ -use std::error::Error; use std::net::SocketAddr; use tokio::io::AsyncWriteExt; use tokio::net::TcpListener; #[tracing::instrument] -pub async fn build_healthcheck_server() -> Result<(), Box> { +pub async fn start_http_server() -> tokio::io::Result<()> { tracing::info!("Starting HTTP server"); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let listener = TcpListener::bind(addr).await?; @@ -17,11 +16,8 @@ pub async fn build_healthcheck_server() -> Result<(), Box> { Err(err) => tracing::info!("Handling connection from unknown peer {}", err), } let response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHealthcheck OK"; - socket - .write_all(response.as_bytes()) - .await - .expect("Failed to write to socket"); - socket.shutdown().await.expect("Failed to shutdown socket"); + let _ = socket.write_all(response.as_bytes()).await; + let _ = socket.shutdown().await; }); } } diff --git a/src/main.rs b/src/main.rs index ae75425..ae64b40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use crate::healthcheck::build_healthcheck_server; -use crate::slack::build_websocket_client; +use crate::healthcheck::start_http_server; +use crate::slack::start_websocket_client; mod healthcheck; mod roulette; @@ -13,10 +13,10 @@ async fn main() { .with_ansi(true) .init(); let app_handle = tokio::spawn(async move { - build_websocket_client().await; + start_websocket_client().await; }); let http_handle = tokio::spawn(async move { - build_healthcheck_server() + start_http_server() .await .expect("Failed to start HTTP server"); }); diff --git a/src/slack.rs b/src/slack.rs index def060d..2268c32 100644 --- a/src/slack.rs +++ b/src/slack.rs @@ -57,7 +57,7 @@ fn create_slack_client() -> Client { /// This function will automatically reconnect to the websocket if the server sends /// a disconnect message. #[tracing::instrument] -pub async fn build_websocket_client() -> () { +pub async fn start_websocket_client() -> () { let client = create_slack_client(); // Perform the initial websocket connection let wss_endpoint = get_websocket_endpoint(&client)