Skip to content

Commit

Permalink
fixing bug in pidgtm compile (#55)
Browse files Browse the repository at this point in the history
* fixing bug in pidgtm compile

Signed-off-by: danbugs <[email protected]>

* fix && fmt

Signed-off-by: danbugs <[email protected]>

---------

Signed-off-by: danbugs <[email protected]>
  • Loading branch information
danbugs authored Dec 28, 2023
1 parent bff494b commit 1a7a10f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 51 deletions.
25 changes: 1 addition & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 12 additions & 0 deletions lib/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(unused)]

use anyhow::Result;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

use std::{
future::Future,
Expand All @@ -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)]
Expand Down
32 changes: 23 additions & 9 deletions lib/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,31 @@ 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);

insert_into(player_sets)
.values(curated_sets)
.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_tournaments)
.values(curated_tournaments)
.execute(&db_connection)?;
if let Err(e) = res {
tracing::error!("🚨 error inserting set into db: {}", e);
}
}

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)
}
Expand Down
9 changes: 5 additions & 4 deletions lib/src/tournament.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ pub fn is_tournament_cached(player_id: i32, s: &SGGSet) -> Result<bool> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use tracing_test::traced_test;

const DANTOTTO_PLAYER_ID: i32 = 1178271;
use crate::common::init_logger;

const HUNGRYBOX_PLAYER_ID: i32 = 1004;

#[traced_test]
#[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(())
}
}
9 changes: 2 additions & 7 deletions src/bin/pidgtm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 2 additions & 6 deletions src/bin/smithe.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1a7a10f

Please sign in to comment.