diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-14 21:50:42 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-14 21:50:42 +0200 |
commit | ec5c91d37b46cb3cec4878176469c66d2304dadd (patch) | |
tree | 16b4dd13605d1a3349a4240f3b25b134af572c84 /planetwars-server/src/modules/ranking.rs | |
parent | 00459f9e3d818f0fb84160862f02898d64f98110 (diff) | |
download | planetwars.dev-ec5c91d37b46cb3cec4878176469c66d2304dadd.tar.xz planetwars.dev-ec5c91d37b46cb3cec4878176469c66d2304dadd.zip |
change runnerconfig to globalconfig
Diffstat (limited to 'planetwars-server/src/modules/ranking.rs')
-rw-r--r-- | planetwars-server/src/modules/ranking.rs | 16 |
1 files changed, 5 insertions, 11 deletions
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<MatchRunnerConfig>, db_pool: DbPool) { +pub async fn run_ranker(config: Arc<GlobalConfig>, 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<MatchRunnerConfig>, 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<MatchRunnerConfig>, - selected_bots: Vec<Bot>, - db_pool: DbPool, -) { +async fn play_ranking_match(config: Arc<GlobalConfig>, selected_bots: Vec<Bot>, 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"); |