Add tracing logging to all commands

This commit is contained in:
Tyler Hallada 2022-06-04 18:51:20 -04:00
parent 8f420c5558
commit bafa405223
9 changed files with 30 additions and 1 deletions

1
.gitignore vendored
View File

@ -4,4 +4,5 @@ plugins.zip
plugins
cells
mods
plugins_data
files

View File

@ -3,6 +3,7 @@ use reqwest::Client;
use std::fs::File;
use std::time::Duration;
use tokio::time::sleep;
use tracing::info;
pub async fn download_tiles(dir: &str) -> Result<()> {
let client = Client::builder().build()?;
@ -18,7 +19,7 @@ pub async fn download_tiles(dir: &str) -> Result<()> {
);
let resp = client.get(&url).send().await?;
if resp.status().is_success() {
println!("{}", url);
info!(z = z, x = x, y = y, "fetched tile from {}", url);
std::fs::create_dir_all(format!("{}/{z}/{x}", dir, z = z, x = x))?;
let mut out =
File::create(format!("{}/{z}/{x}/{y}.jpg", dir, z = z, x = x, y = y))?;

View File

@ -2,6 +2,7 @@ use anyhow::Result;
use std::fs::{create_dir_all, File};
use std::io::Write;
use std::path::Path;
use tracing::info;
use crate::models::cell;
@ -13,6 +14,7 @@ pub async fn dump_cell_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str) -> Res
let path = Path::new(&path);
create_dir_all(&path)?;
let path = path.join(format!("{}.json", y));
info!(x = x, y = y, form_id = data.form_id, "dumping cell data to {}", path.display());
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&data)?)?;
}

View File

@ -2,6 +2,7 @@ use anyhow::Result;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use tracing::info;
use crate::models::cell;
@ -10,10 +11,12 @@ pub async fn dump_cell_edit_counts(pool: &sqlx::Pool<sqlx::Postgres>, path: &str
for x in -77..75 {
for y in -50..44 {
if let Some(count) = cell::count_mod_edits(&pool, "Skyrim.esm", 1, x, y).await? {
info!(x = x, y = y, count = count, "read cell edit count");
cell_mod_edit_counts.insert(format!("{},{}", x, y), count);
}
}
}
info!("writing {} cell edit counts to {}", cell_mod_edit_counts.len(), path);
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&cell_mod_edit_counts)?)?;
return Ok(());

View File

@ -3,10 +3,12 @@ use chrono::NaiveDateTime;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use tracing::info;
use crate::models::file;
pub async fn dump_file_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated_after: Option<NaiveDateTime>) -> Result<()> {
let mut page = 1;
let page_size = 20;
let mut last_id = None;
loop {
@ -19,10 +21,12 @@ pub async fn dump_file_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, update
let path = Path::new(&dir);
std::fs::create_dir_all(&path)?;
let path = path.join(format!("{}.json", file_with_cells.nexus_file_id));
info!(page = page, nexus_file_id = file_with_cells.nexus_file_id, "dumping file data to {}", path.display());
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&file_with_cells)?)?;
last_id = Some(file_with_cells.id);
}
page += 1;
}
return Ok(());
}

View File

@ -2,10 +2,12 @@ use anyhow::Result;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use tracing::info;
use crate::models::game_mod;
pub async fn dump_mod_cell_counts(pool: &sqlx::Pool<sqlx::Postgres>, path: &str) -> Result<()> {
let mut page = 1;
let page_size = 100;
let mut last_id = None;
let mut counts = HashMap::new();
@ -16,10 +18,13 @@ pub async fn dump_mod_cell_counts(pool: &sqlx::Pool<sqlx::Postgres>, path: &str)
break;
}
for mod_cell_count in mod_cell_counts {
info!(page = page, nexus_mod_id = mod_cell_count.nexus_mod_id, count = mod_cell_count.cells.unwrap_or(0), "read mod cell count");
counts.insert(mod_cell_count.nexus_mod_id, mod_cell_count.cells);
last_id = Some(mod_cell_count.nexus_mod_id);
}
page += 1;
}
info!("writing {} mod cell counts to {}", counts.len(), path);
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&counts)?)?;
return Ok(());

View File

@ -3,10 +3,12 @@ use chrono::NaiveDateTime;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use tracing::info;
use crate::models::game_mod;
pub async fn dump_mod_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated_after: Option<NaiveDateTime>) -> Result<()> {
let mut page = 1;
let page_size = 20;
let mut last_id = None;
loop {
@ -19,10 +21,12 @@ pub async fn dump_mod_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated
let path = Path::new(&dir);
std::fs::create_dir_all(&path)?;
let path = path.join(format!("{}.json", mod_with_cells.nexus_mod_id));
info!(page = page, nexus_mod_id = mod_with_cells.nexus_mod_id, "dumping mod data to {}", path.display());
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&mod_with_cells)?)?;
last_id = Some(mod_with_cells.id);
}
page += 1;
}
return Ok(());
}

View File

@ -2,6 +2,7 @@ use anyhow::Result;
use serde::Serialize;
use std::fs::File;
use std::io::Write;
use tracing::info;
use crate::models::game_mod;
@ -12,6 +13,7 @@ struct ModForSearchIdTranslated {
}
pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, path: &str) -> Result<()> {
let mut page = 1;
let mut search_index = vec![];
let page_size = 20;
let mut last_id = None;
@ -21,13 +23,16 @@ pub async fn dump_mod_search_index(pool: &sqlx::Pool<sqlx::Postgres>, path: &str
break;
}
for mod_for_search in mods {
info!(page = page, nexus_mod_id = mod_for_search.nexus_mod_id, "read mod name for search index");
search_index.push(ModForSearchIdTranslated {
name: mod_for_search.name,
id: mod_for_search.nexus_mod_id,
});
last_id = Some(mod_for_search.id);
}
page += 1;
}
info!("writing {} mod names for search index to {}", search_index.len(), path);
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&search_index)?)?;
return Ok(());

View File

@ -3,6 +3,7 @@ use chrono::NaiveDateTime;
use std::fs::{create_dir_all, File};
use std::io::Write;
use std::path::Path;
use tracing::info;
use crate::models::plugin;
@ -23,6 +24,7 @@ fn format_radix(mut x: u64, radix: u32) -> String {
}
pub async fn dump_plugin_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated_after: Option<NaiveDateTime>) -> Result<()> {
let mut page: u32 = 1;
let page_size = 20;
let mut last_hash = None;
loop {
@ -35,10 +37,12 @@ pub async fn dump_plugin_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, upda
let path = Path::new(&dir);
create_dir_all(&path)?;
let path = path.join(format!("{}.json", format_radix(plugin.hash as u64, 36)));
info!(page = page, hash = plugin.hash, "dumping plugin data to {}", path.display());
let mut file = File::create(path)?;
write!(file, "{}", serde_json::to_string(&plugin)?)?;
last_hash = Some(plugin.hash);
}
page += 1;
}
Ok(())
}