From a3766980735851e9aa4b56a80e91c0b77cf63adb Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Fri, 10 Jun 2022 21:49:32 +0200 Subject: update RunMatch helper to allow for remote bots --- planetwars-server/src/modules/ranking.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index f76fbae..d83debb 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -1,7 +1,7 @@ use crate::{db::bots::Bot, DbPool}; use crate::db; -use crate::modules::matches::RunMatch; +use crate::modules::matches::{MatchPlayer, RunMatch}; use rand::seq::SliceRandom; use std::time::Duration; use tokio; @@ -43,9 +43,12 @@ async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { code_bundles.push(code_bundle); } - let code_bundle_refs = code_bundles.iter().map(|b| b).collect::>(); + let players = code_bundles + .iter() + .map(MatchPlayer::from_code_bundle) + .collect::>(); - let mut run_match = RunMatch::from_players(code_bundle_refs); + let mut run_match = RunMatch::from_players(players); run_match .store_in_database(&db_conn) .expect("could not store match in db"); -- cgit v1.2.3 From b3df5c6f8cc59e099a2f1db3df8089af4abca02e Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 5 Jul 2022 20:34:20 +0200 Subject: migrate code_bundles to bot_versions --- planetwars-server/src/modules/ranking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 72156ee..b1ad0da 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -1,8 +1,8 @@ use crate::{db::bots::Bot, DbPool}; use crate::db; -use diesel::{PgConnection, QueryResult}; use crate::modules::matches::{MatchPlayer, RunMatch}; +use diesel::{PgConnection, QueryResult}; use rand::seq::SliceRandom; use std::collections::HashMap; use std::mem; -- cgit v1.2.3 From d7b7585dd70f9d41184cf88c2ecbd88341898c38 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 6 Jul 2022 22:41:27 +0200 Subject: rename code_bundle to bot_version --- planetwars-server/src/modules/ranking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index b1ad0da..751c35e 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -39,7 +39,7 @@ async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { let db_conn = db_pool.get().await.expect("could not get db pool"); let mut code_bundles = Vec::new(); for bot in &selected_bots { - let code_bundle = db::bots::active_code_bundle(bot.id, &db_conn) + let code_bundle = db::bots::active_bot_version(bot.id, &db_conn) .expect("could not get active code bundle"); code_bundles.push(code_bundle); } -- cgit v1.2.3 From ec1d50f655c05d9dec0c4b01fd1039e9c5525f34 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 9 Jul 2022 20:01:05 +0200 Subject: refactor: pass on both Bot and BotVersion to MatchPlayer --- planetwars-server/src/modules/ranking.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 751c35e..3182ce2 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -37,18 +37,14 @@ pub async fn run_ranker(db_pool: DbPool) { async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { let db_conn = db_pool.get().await.expect("could not get db pool"); - let mut code_bundles = Vec::new(); + let mut players = Vec::new(); for bot in &selected_bots { - let code_bundle = db::bots::active_bot_version(bot.id, &db_conn) - .expect("could not get active code bundle"); - code_bundles.push(code_bundle); + let version = db::bots::active_bot_version(bot.id, &db_conn) + .expect("could not get active bot version"); + let player = MatchPlayer::from_bot_version(bot, &version); + players.push(player); } - let players = code_bundles - .iter() - .map(MatchPlayer::from_code_bundle) - .collect::>(); - let mut run_match = RunMatch::from_players(players); run_match .store_in_database(&db_conn) -- cgit v1.2.3 From e69bd14f1d64b0d8b2438a40a069d3647c1edd73 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 12 Jul 2022 20:54:00 +0200 Subject: refactor: delay BotSpec construction in RunMatch --- planetwars-server/src/modules/ranking.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 3182ce2..7147b98 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -41,7 +41,10 @@ async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { for bot in &selected_bots { let version = db::bots::active_bot_version(bot.id, &db_conn) .expect("could not get active bot version"); - let player = MatchPlayer::from_bot_version(bot, &version); + let player = MatchPlayer::BotVersion { + bot: Some(bot.clone()), + version, + }; players.push(player); } -- cgit v1.2.3 From 668409e76d8cc7797fe627b2e2c3d0223b3db684 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 13 Jul 2022 19:36:07 +0200 Subject: refactor: unify match save and spawn --- planetwars-server/src/modules/ranking.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 7147b98..1c35394 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -48,14 +48,12 @@ async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { players.push(player); } - let mut run_match = RunMatch::from_players(players); - run_match - .store_in_database(&db_conn) - .expect("could not store match in db"); - run_match - .spawn(db_pool.clone()) + let (_, handle) = RunMatch::from_players(players) + .run(db_pool.clone()) .await - .expect("running match failed"); + .expect("failed to run match"); + // wait for match to complete, so that only one ranking match can be running + let _outcome = handle.await; } fn recalculate_ratings(db_conn: &PgConnection) -> QueryResult<()> { -- cgit v1.2.3 From 00459f9e3d818f0fb84160862f02898d64f98110 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 14 Jul 2022 20:53:08 +0200 Subject: create a configuration to hold docker registry url --- planetwars-server/src/modules/ranking.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 1c35394..e483d1c 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -6,12 +6,15 @@ use diesel::{PgConnection, QueryResult}; use rand::seq::SliceRandom; use std::collections::HashMap; use std::mem; +use std::sync::Arc; use std::time::{Duration, Instant}; use tokio; +use super::matches::MatchRunnerConfig; + const RANKER_INTERVAL: u64 = 60; -pub async fn run_ranker(db_pool: DbPool) { +pub async fn run_ranker(runner_config: Arc, db_pool: DbPool) { // TODO: make this configurable // play at most one match every n seconds let mut interval = tokio::time::interval(Duration::from_secs(RANKER_INTERVAL)); @@ -30,12 +33,16 @@ pub async fn run_ranker(db_pool: DbPool) { let mut rng = &mut rand::thread_rng(); bots.choose_multiple(&mut rng, 2).cloned().collect() }; - play_ranking_match(selected_bots, db_pool.clone()).await; + play_ranking_match(runner_config.clone(), selected_bots, db_pool.clone()).await; recalculate_ratings(&db_conn).expect("could not recalculate ratings"); } } -async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { +async fn play_ranking_match( + runner_config: Arc, + selected_bots: Vec, + db_pool: DbPool, +) { let db_conn = db_pool.get().await.expect("could not get db pool"); let mut players = Vec::new(); for bot in &selected_bots { @@ -48,7 +55,7 @@ async fn play_ranking_match(selected_bots: Vec, db_pool: DbPool) { players.push(player); } - let (_, handle) = RunMatch::from_players(players) + let (_, handle) = RunMatch::from_players(runner_config, players) .run(db_pool.clone()) .await .expect("failed to run match"); -- cgit v1.2.3 From ec5c91d37b46cb3cec4878176469c66d2304dadd Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 14 Jul 2022 21:50:42 +0200 Subject: change runnerconfig to globalconfig --- planetwars-server/src/modules/ranking.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'planetwars-server/src/modules/ranking.rs') diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index e483d1c..a9f6419 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -1,4 +1,4 @@ -use crate::{db::bots::Bot, DbPool}; +use crate::{db::bots::Bot, DbPool, GlobalConfig}; use crate::db; use crate::modules::matches::{MatchPlayer, RunMatch}; @@ -10,11 +10,9 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use tokio; -use super::matches::MatchRunnerConfig; - const RANKER_INTERVAL: u64 = 60; -pub async fn run_ranker(runner_config: Arc, db_pool: DbPool) { +pub async fn run_ranker(config: Arc, db_pool: DbPool) { // TODO: make this configurable // play at most one match every n seconds let mut interval = tokio::time::interval(Duration::from_secs(RANKER_INTERVAL)); @@ -33,16 +31,12 @@ pub async fn run_ranker(runner_config: Arc, db_pool: DbPool) let mut rng = &mut rand::thread_rng(); bots.choose_multiple(&mut rng, 2).cloned().collect() }; - play_ranking_match(runner_config.clone(), selected_bots, db_pool.clone()).await; + play_ranking_match(config.clone(), selected_bots, db_pool.clone()).await; recalculate_ratings(&db_conn).expect("could not recalculate ratings"); } } -async fn play_ranking_match( - runner_config: Arc, - selected_bots: Vec, - db_pool: DbPool, -) { +async fn play_ranking_match(config: Arc, selected_bots: Vec, db_pool: DbPool) { let db_conn = db_pool.get().await.expect("could not get db pool"); let mut players = Vec::new(); for bot in &selected_bots { @@ -55,7 +49,7 @@ async fn play_ranking_match( players.push(player); } - let (_, handle) = RunMatch::from_players(runner_config, players) + let (_, handle) = RunMatch::from_players(config, players) .run(db_pool.clone()) .await .expect("failed to run match"); -- cgit v1.2.3