From dcc90f02956b8342925bc2a67d9b3019660ebe89 Mon Sep 17 00:00:00 2001 From: danbugs Date: Wed, 27 Dec 2023 16:38:40 -0800 Subject: [PATCH] fixing bug in pidgtm compile Signed-off-by: danbugs --- Cargo.lock | 25 +------------------------ lib/Cargo.toml | 2 +- lib/src/common.rs | 12 ++++++++++++ lib/src/player.rs | 36 +++++++++++++++++++++++++++--------- lib/src/tournament.rs | 9 +++++---- src/bin/pidgtm.rs | 9 ++------- src/bin/smithe.rs | 8 ++------ 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81f100f..7f915ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1740,7 +1740,7 @@ dependencies = [ "startgg", "tokio", "tracing", - "tracing-test", + "tracing-subscriber", ] [[package]] @@ -2088,29 +2088,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "tracing-test" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" -dependencies = [ - "lazy_static", - "tracing-core", - "tracing-subscriber", - "tracing-test-macro", -] - -[[package]] -name = "tracing-test-macro" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" -dependencies = [ - "lazy_static", - "quote", - "syn 1.0.99", -] - [[package]] name = "try-lock" version = "0.2.3" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 318ac30..8b82a03 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -11,11 +11,11 @@ test = false [dependencies] anyhow = "1" tracing = "0.1" +tracing-subscriber = "0.3" diesel = { version = "1.4", features = ["postgres"] } smithe_database = { path = "../database" } startgg = { path = "../startgg_api" } ctrlc = "3.2" as-any = "0.3" tokio = { version = "1.1", features = [ "rt", "macros" ] } -tracing-test = "0.2" chrono = "0.4" diff --git a/lib/src/common.rs b/lib/src/common.rs index a205264..b38c431 100644 --- a/lib/src/common.rs +++ b/lib/src/common.rs @@ -1,6 +1,8 @@ #![allow(unused)] use anyhow::Result; +use tracing::Level; +use tracing_subscriber::FmtSubscriber; use std::{ future::Future, @@ -13,6 +15,16 @@ use std::{ time::{Duration, Instant}, }; +pub fn init_logger() -> Result<()> { + let subscriber = FmtSubscriber::builder() + .with_max_level(Level::INFO) + .finish(); + + tracing::subscriber::set_global_default(subscriber)?; + + Ok(()) +} + use startgg::{GQLData, GQLVars}; #[allow(clippy::too_many_arguments)] diff --git a/lib/src/player.rs b/lib/src/player.rs index 261b1e2..dd834c2 100644 --- a/lib/src/player.rs +++ b/lib/src/player.rs @@ -343,17 +343,35 @@ where // we want to panic regardless } - insert_into(player_games) - .values(curated_games) - .execute(&db_connection)?; + for g in curated_games { + let res = insert_into(player_games) + .values(g) + .execute(&db_connection); + + if let Err(e) = res { + tracing::error!("🚨 error inserting game into db: {}", e); + } + } + + for s in curated_sets { + let res = insert_into(player_sets) + .values(s) + .execute(&db_connection); - insert_into(player_sets) - .values(curated_sets) - .execute(&db_connection)?; + if let Err(e) = res { + tracing::error!("🚨 error inserting set into db: {}", e); + } + } - insert_into(player_tournaments) - .values(curated_tournaments) - .execute(&db_connection)?; + for t in curated_tournaments { + let res = insert_into(player_tournaments) + .values(t) + .execute(&db_connection); + + if let Err(e) = res { + tracing::error!("🚨 error inserting tournament into db: {}", e); + } + } Ok(false) } diff --git a/lib/src/tournament.rs b/lib/src/tournament.rs index f826840..26e204c 100644 --- a/lib/src/tournament.rs +++ b/lib/src/tournament.rs @@ -128,14 +128,15 @@ pub fn is_tournament_cached(player_id: i32, s: &SGGSet) -> Result { #[cfg(test)] mod tests { use anyhow::Result; - use tracing_test::traced_test; - const DANTOTTO_PLAYER_ID: i32 = 1178271; + use crate::common::init_logger; - #[traced_test] + const HUNGRYBOX_PLAYER_ID: i32 = 1004; + #[tokio::test] async fn get_tournaments_from_requester_id_test() -> Result<()> { - let _ = super::get_tournaments_from_requester_id(DANTOTTO_PLAYER_ID).await?; + init_logger()?; + let _ = super::get_tournaments_from_requester_id(HUNGRYBOX_PLAYER_ID).await?; Ok(()) } } diff --git a/src/bin/pidgtm.rs b/src/bin/pidgtm.rs index 9fdd4a6..7f6563a 100644 --- a/src/bin/pidgtm.rs +++ b/src/bin/pidgtm.rs @@ -2,11 +2,10 @@ use std::env; use anyhow::Result; use clap::{Parser, Subcommand}; +use smithe_lib::common::init_logger; use smithereens::pidgtm::{ compile::handle_compile, inspect::handle_inspect, map::handle_map, update::handle_update, }; -use tracing::Level; -use tracing_subscriber::FmtSubscriber; /// pidgtm stands for "player id to gamer tag mapper". This is a CLI that allows /// direct user access to the engine that powers searching players by name. @@ -43,11 +42,7 @@ enum Commands { #[tokio::main] async fn main() -> Result<()> { - let subscriber = FmtSubscriber::builder() - .with_max_level(Level::INFO) - .finish(); - - tracing::subscriber::set_global_default(subscriber)?; + init_logger()?; let cli = Cli::parse(); diff --git a/src/bin/smithe.rs b/src/bin/smithe.rs index 4c3dc4e..47add82 100644 --- a/src/bin/smithe.rs +++ b/src/bin/smithe.rs @@ -1,7 +1,6 @@ use anyhow::Result; +use smithe_lib::common::init_logger; use std::str::FromStr; -use tracing::Level; -use tracing_subscriber::FmtSubscriber; use clap::{Parser, Subcommand}; use smithereens::smithe::{event::handle_event, player::handle_player}; @@ -32,11 +31,8 @@ enum Commands { #[tokio::main] async fn main() -> Result<()> { - let subscriber = FmtSubscriber::builder() - .with_max_level(Level::INFO) - .finish(); + init_logger()?; - tracing::subscriber::set_global_default(subscriber)?; let cli = Cli::parse(); match &cli.command {