From 51bfc72f56d6cda25b8f56efac78d2c681cb8596 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sat, 20 Apr 2024 19:53:10 +0200 Subject: [PATCH] some fixes and logging --- Cargo.lock | 3 +-- Cargo.toml | 2 +- src/client.rs | 8 ++++---- src/main.rs | 7 ++++++- src/prelude.rs | 2 -- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30e7572..56a63af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3372,7 +3372,6 @@ dependencies = [ [[package]] name = "twba-twitch-data" version = "0.3.0" -source = "git+https://github.com/OMGeeky/twitch_data.git#908cbae28ff0c7b13e00a942955776c1c0e14707" dependencies = [ "anyhow", "async-recursion", @@ -3396,7 +3395,7 @@ dependencies = [ ] [[package]] -name = "twitch-fetcher" +name = "twba-twitch-fetcher" version = "0.1.0" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 72b9d80..e7e2510 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "twitch-fetcher" +name = "twba-twitch-fetcher" version = "0.1.0" edition = "2021" diff --git a/src/client.rs b/src/client.rs index d0b8567..2e8f353 100644 --- a/src/client.rs +++ b/src/client.rs @@ -56,16 +56,16 @@ impl<'a> FetcherClient<'a> { .await .map_err(FetcherError::GetVideosError)?; for video in videos { - info!("Adding video: {} to the database", video.title); let existing_video_found = Videos::find() .filter(VideosColumn::TwitchId.eq(video.id.to_string())) .one(&self.db) - .await - .is_ok(); + .await? + .is_some(); if existing_video_found { info!("Video with id: {} already exists in the database", video.id); continue; } + info!("Adding video: {} to the database", video.title); ActiveModel { id: ActiveValue::NotSet, @@ -74,7 +74,7 @@ impl<'a> FetcherClient<'a> { user_id: ActiveValue::Set(user.id), created_at: ActiveValue::Set(video.created_at.to_rfc3339()), youtube_id: ActiveValue::NotSet, - youtube_playlist_name: ActiveValue::NotSet, + youtube_playlist_name: ActiveValue::Set("".to_string()), youtube_preview_image_url: ActiveValue::NotSet, youtube_playlist_id: ActiveValue::NotSet, duration: ActiveValue::Set(video.duration as i32), diff --git a/src/main.rs b/src/main.rs index 3ad47ce..55667d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ async fn main() -> Result<()> { tracing_subscriber::fmt() .with_max_level(tracing::Level::INFO) .with_env_filter( - "sea_orm=warn,sea_orm_migration=warn,sqlx=warn,twba_fetcher=trace,twba_local_db=warn,twba_twitch_data=info,twba_downloader_config=info,twba_backup_config=info,other=warn", + "sea_orm=warn,sea_orm_migration=warn,sqlx=warn,twba_twitch_fetcher=trace,twba_local_db=warn,twba_twitch_data=info,twba_downloader_config=info,twba_backup_config=info,other=warn", ) .init(); info!("Hello, world!"); @@ -29,13 +29,18 @@ async fn run() -> Result<()> { .load() .map_err(|e| FetcherError::LoadConfig(e.into()))?; + trace!("Opening database"); let db = twba_local_db::open_database(Some(&conf.db_url)).await?; twba_local_db::migrate_db(&db).await?; + trace!("Creating twitch client"); let twitch_client = twba_twitch_data::get_client() .await .map_err(FetcherError::CreateClientError)?; + info!("Creating client"); let client = client::FetcherClient::new(conf, db, twitch_client); + info!("Fetching new videos"); client.fetch_new_videos().await?; + info!("Done fetching new videos"); Ok(()) } diff --git a/src/prelude.rs b/src/prelude.rs index ef0d9c2..fcc5a9a 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,5 +1,3 @@ -use twba_backup_config::Conf; - pub use crate::errors::FetcherError; pub(crate) use std::result::Result as StdResult; pub(crate) use tracing::{debug, error, info, trace, warn};