Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Apr 1, 2024
1 parent 1526147 commit 6b1b343
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ cargo run
# Docker
docker build -t pizzapicker:latest .
docker run -e SLACK_APP_TOKEN=<your_token> pizzapicker:latest

docker tag pizzapicker:latest <aws_account_id>.dkr.ecr.eu-north-1.amazonaws.com/pizzapicker-prod:latest
docker push <aws_account_id>.dkr.ecr.eu-north-1.amazonaws.com/pizzapicker-prod:latest
```

## License
Expand Down
10 changes: 3 additions & 7 deletions src/healthcheck.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
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?;
Expand All @@ -17,11 +16,8 @@ pub async fn build_healthcheck_server() -> Result<(), Box<dyn Error>> {
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;
});
}
}
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
});
Expand Down
2 changes: 1 addition & 1 deletion src/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6b1b343

Please sign in to comment.