Fix tracing logging to use only tracing and get instrument/spans going

This commit is contained in:
2025-06-28 15:48:09 -04:00
parent 6c6b766b72
commit 91d8efe5bb
3 changed files with 28 additions and 51 deletions

View File

@@ -7,7 +7,13 @@ use ebay_scraper_rust::db::{
use ebay_scraper_rust::{parser_ebay, parser_storage};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use tracing::info;
use std::time::Instant;
use tracing::{error, info, instrument};
use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::fmt;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
mod xdg_dirs;
@@ -94,7 +100,6 @@ pub fn timestamps_from_dir(path: &Path) -> Vec<i64> {
std::fs::read_dir(path)
.unwrap()
.inspect(|fpath| info!("Found {:?}", fpath))
.map(|fpath| fpath.unwrap().path())
.filter_map(|fstem| {
fstem
@@ -108,6 +113,7 @@ pub fn timestamps_from_dir(path: &Path) -> Vec<i64> {
}
#[post("page/parse/{category}")]
#[instrument(skip_all)]
async fn parse_post(
db: Data<Mutex<rusqlite::Connection>>,
downloaddir: Data<PathBuf>,
@@ -135,21 +141,33 @@ async fn parse_post(
// Timestamp never seen before, lets pass it on.
if p.is_none() {
info!(
"Page of timestamp:{} and catagory:{category} never seen before, processing ...",
ts.timestamp()
);
return true;
}
// Timestamp was seen before *and* from the same catagory, don't pass
// it on.
if p.unwrap().category == *category {
info!(
"Page of timestamp:{} and catagory:{category} seen before, skipping ...",
ts.timestamp()
);
return false;
}
info!(
"Page of timestamp:{} seen before, but not of catagory:{category}, processing ...",
ts.timestamp()
);
return true;
});
let mut added_count = 0;
for p in to_parse {
let ts = chrono::DateTime::from_timestamp(*p, 0).unwrap();
info!("Adding page with a timestamp of {ts} and catagory of {category} to db");
ParsedPage {
timestamp: ts,
category: category.to_string(),
@@ -171,12 +189,16 @@ async fn parse_post(
}
}
info!("Added {added_count} listings");
Ok(added_count.to_string())
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init();
let _ = Args::parse();
let scrapedatadir = xdg_dirs::ensure_scrapedata_dir_exists("ebay_scraper", None);