Skip to content

Commit

Permalink
Fix API endpoint and update running status in game_result.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwaeseperlman committed Feb 25, 2024
1 parent 556ed80 commit 5ea0dd9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion website/app/src/ManageTeam/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function TeamStats({ team }: { team: TeamWithMembers<User> }) {

useEffect(() => {
const getGames = () => {
fetch(`${apiUrl}/count-games?team_id=${team.id}`).then(async (res) => {
fetch(`${apiUrl}/count-games?team=${team.id}`).then(async (res) => {
const json = await res.json();
if (res.status === 200) {
setGamesPlayed(json);
Expand Down
11 changes: 6 additions & 5 deletions workers/results/src/game_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ pub async fn handle_game_result(status: GameStatusMessage) -> Result<(), ()> {
.set(&new_result)
.execute(db_conn)?;
log::debug!("Inserted game result for {}", id.clone());
diesel::update(games::table.find(id.clone()))
.set(games::dsl::running.eq(false))
.execute(db_conn)?;
log::debug!("Not running for {}", id.clone());
}
Ok(GameStatus::TestGameSucceeded) => {
// set the active bot for the team if they don't have one
Expand Down Expand Up @@ -240,6 +236,11 @@ pub async fn handle_game_result(status: GameStatusMessage) -> Result<(), ()> {
Ok::<(), diesel::result::Error>(())
})
.map_err(|_| ())?;
save_game_details(id).await?;

// Don't fail if we can't save the game details
if let Err(_) = save_game_details(id.clone()).await {
log::error!("Failed to save game details for {}", id);
}

Ok(())
}
17 changes: 16 additions & 1 deletion workers/results/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use aws_sdk_s3::presigning::PresigningConfig;
use diesel::prelude::*;
use results::build_result::handle_build_result;
use results::game_result::{handle_game_result, save_game_details};
use shared::sqs::listen_on_queue;
Expand Down Expand Up @@ -56,7 +57,21 @@ async fn main() {
&sqs,
|task: GameStatusMessage| async move {
log::info!("Received game result: {:?}", task);
handle_game_result(task).await.is_ok()
let id = task.id.clone();
let result = handle_game_result(task).await.is_ok();
if let Ok(mut db_conn) = shared::db::conn::DB_CONNECTION.get() {
let db_conn = &mut (*db_conn);
if let Err(_) = diesel::update(shared::db::schema::games::table.find(id.clone()))
.set(shared::db::schema::games::dsl::running.eq(false))
.execute(db_conn) {
log::error!("Failed to update running status of {}", id.clone());
}
}
else {
log::error!("Failed to update running status of {}", id.clone());

}
result
},
|err| log::error!("Error receiving game result: {}", err),
),
Expand Down

0 comments on commit 5ea0dd9

Please sign in to comment.