some fixes and logging

This commit is contained in:
OMGeeky
2024-04-20 19:53:10 +02:00
parent fc4add0f02
commit 51bfc72f56
5 changed files with 12 additions and 10 deletions

3
Cargo.lock generated
View File

@@ -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",

View File

@@ -1,5 +1,5 @@
[package]
name = "twitch-fetcher"
name = "twba-twitch-fetcher"
version = "0.1.0"
edition = "2021"

View File

@@ -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),

View File

@@ -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(())
}

View File

@@ -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};