Skip to content

Commit

Permalink
Added basic error metrics to the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Lol3rrr committed Nov 6, 2023
1 parent bf341c6 commit 2eec9cb
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 18 deletions.
121 changes: 121 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ prometheus = { version = "0.13.3" }
aws-creds = { version = "0.36.0", default_features = false, features = ["http-credentials", "rustls-tls"]}
rust-s3 = { version = "0.33.0", default_features = false, features = [ "tokio", "tokio-rustls-tls", "no-verify-ssl"] }
clap = { version = "4.4.7", features = ["derive"] }
axum = "0.6.20"
once_cell = "1.18.0"
42 changes: 31 additions & 11 deletions src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,16 @@ impl Client {
}

#[tracing::instrument(skip(client, clan_season_stats))]
pub async fn update_names(client: &Client, clan: &ClanTag, clan_season_stats: &mut ClanStorage) {
pub async fn update_names(
client: &Client,
clan: &ClanTag,
clan_season_stats: &mut ClanStorage,
) -> Result<(), ()> {
let info = match client.clan_info(clan).await {
Ok(i) => i,
Err(e) => {
tracing::error!("Failed to load Clan Information {:?}", e);
return;
return Err(());
}
};

Expand All @@ -343,15 +347,17 @@ pub async fn update_names(client: &Client, clan: &ClanTag, clan_season_stats: &m
.player_names
.insert(member.tag, member.name);
}

Ok(())
}

#[tracing::instrument(skip(client, storage))]
pub async fn update_cwl(client: &Client, clan: &ClanTag, storage: &mut Storage) {
pub async fn update_cwl(client: &Client, clan: &ClanTag, storage: &mut Storage) -> Result<(), ()> {
let w = match client.clan_war_league_group(clan).await {
Ok(w) => w,
Err(e) => {
tracing::error!("Loading Clan War League Group: {:?}", e);
return;
return Err(());
}
};

Expand Down Expand Up @@ -410,37 +416,43 @@ pub async fn update_cwl(client: &Client, clan: &ClanTag, storage: &mut Storage)
}
}
}

Ok(())
}

#[tracing::instrument(skip(client, storage))]
pub async fn update_war(client: &Client, clan_tag: &ClanTag, storage: &mut Storage) {
pub async fn update_war(
client: &Client,
clan_tag: &ClanTag,
storage: &mut Storage,
) -> Result<(), ()> {
let war = match client.war().current(&clan_tag).await {
Ok(w) => w,
Err(e) => {
tracing::error!("Error loading War: {:?}", e);
return;
return Err(());
}
};

if !matches!(war.state, CurrentWarState::InWar) {
tracing::info!("WAR: Not in War currently {:?}", war.state);
return;
return Ok(());
}

let clan = war.clan;
let members = match clan.members {
Some(m) => m,
None => {
tracing::error!("Current War Clan is missing Members");
return;
return Err(());
}
};

let start_time = match war.start_time {
Some(t) => t,
None => {
tracing::error!("Current War missing Start Time");
return;
return Err(());
}
};

Expand Down Expand Up @@ -475,15 +487,21 @@ pub async fn update_war(client: &Client, clan_tag: &ClanTag, storage: &mut Stora
.collect(),
};
clan_season_stats.wars.insert(start_time, war_stats);

Ok(())
}

#[tracing::instrument(skip(client, storage))]
pub async fn update_clan_games(client: &Client, clan_tag: &ClanTag, storage: &mut Storage) {
pub async fn update_clan_games(
client: &Client,
clan_tag: &ClanTag,
storage: &mut Storage,
) -> Result<(), ()> {
let clan = match client.clan_info(&clan_tag).await {
Ok(clan) => clan,
Err(e) => {
tracing::error!("Loading Clan Information: {:?}", e);
return;
return Err(());
}
};

Expand Down Expand Up @@ -526,4 +544,6 @@ pub async fn update_clan_games(client: &Client, clan_tag: &ClanTag, storage: &mu
}
}
}

Ok(())
}
Loading

0 comments on commit 2eec9cb

Please sign in to comment.