diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 22:22:45 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 22:22:45 +0200 |
commit | eb2cbb15fbea6dd6f800598329cd5cc892090d7b (patch) | |
tree | 7768204300a54b0bc4e71f3bb3f82519e8aa3196 /planetwars-server/src/modules/matches.rs | |
parent | 2278ecd2584050c28e62f0f5fd8967b81d64cc5b (diff) | |
download | planetwars.dev-eb2cbb15fbea6dd6f800598329cd5cc892090d7b.tar.xz planetwars.dev-eb2cbb15fbea6dd6f800598329cd5cc892090d7b.zip |
save matchplayer had_errors in database
Diffstat (limited to 'planetwars-server/src/modules/matches.rs')
-rw-r--r-- | planetwars-server/src/modules/matches.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index 71e8a98..489a9fa 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -1,4 +1,4 @@ -use diesel::{PgConnection, QueryResult}; +use diesel::{Connection, PgConnection, QueryResult}; use planetwars_matchrunner::{self as runner, docker_runner::DockerBotSpec, BotSpec, MatchConfig}; use runner::MatchOutcome; use std::{path::PathBuf, sync::Arc}; @@ -176,8 +176,14 @@ async fn run_match_task( winner: outcome.winner.map(|w| (w - 1) as i32), // player numbers in matchrunner start at 1 }; - db::matches::save_match_result(match_id, result, &mut conn) - .expect("could not save match result"); + conn.transaction(|conn| { + for (player_id, player_outcome) in outcome.player_outcomes.iter().enumerate() { + let had_errors = player_outcome.had_errors || player_outcome.crashed; + db::matches::set_player_had_errors(match_id, player_id as i32, had_errors, conn)?; + } + db::matches::save_match_result(match_id, result, conn) + }) + .expect("could not save match result"); outcome } |