diff --git a/Cargo.toml b/Cargo.toml index 49a7889..e92760e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -twba-backup-config = { version = "0.1", git="https://github.com/OMGeeky/backup_config.git" } -twba-local-db = { version = "0.2", git="https://github.com/OMGeeky/twitch_backup.local_db.git" } +twba-backup-config = { version = "0.1", git = "https://github.com/OMGeeky/backup_config.git" } +twba-local-db = { version = "0.2", git = "https://github.com/OMGeeky/twitch_backup.local_db.git" } +twba-common = { version = "0.1", git = "https://github.com/OMGeeky/twba.common.git" } tokio = "1.33" tracing = "0.1" diff --git a/src/client.rs b/src/client.rs index cda96ad..77a5abe 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,15 +1,15 @@ use crate::errors::SplitterError; use crate::prelude::*; -use twba_backup_config::Conf; use chrono::Duration; -use twba_local_db::prelude::{Status, Videos, VideosColumn, VideosModel}; -use twba_local_db::re_exports::sea_orm::{ - ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, - QueryFilter, -}; use std::path::{Path, PathBuf}; use std::time::Instant; use tokio::fs; +use twba_backup_config::Conf; +use twba_local_db::prelude::{Status, Videos, VideosColumn, VideosModel}; +use twba_local_db::re_exports::sea_orm::{ + ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, + QueryFilter, QuerySelect, +}; mod utils; use utils::ffmpeg::run_ffmpeg_split; @@ -43,7 +43,10 @@ impl SplitterClient { video.clone().update(&self.db).await?; } Err(err) => { - error!("Could not split video with id: {} because of err: {:?}", id, err); + error!( + "Could not split video with id: {} because of err: {:?}", + id, err + ); video.status = ActiveValue::Set(Status::SplitFailed); video.clone().update(&self.db).await?; return Err(err); @@ -120,6 +123,7 @@ impl SplitterClient { info!("Splitting videos"); let videos = Videos::find() .filter(VideosColumn::Status.eq(Status::Downloaded)) + .limit(self.conf.max_items_to_process) .all(&self.db) .await?; diff --git a/src/main.rs b/src/main.rs index 8f41c0a..7f63695 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,12 +8,7 @@ pub mod errors; pub mod prelude; #[tokio::main] 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_splitter=trace,twba_local_db=warn,other=warn", - ) - .init(); + let _guard = twba_common::init_tracing("twba_splitter"); info!("Hello, world!"); run().await?; @@ -22,11 +17,7 @@ async fn main() -> Result<()> { Ok(()) } async fn run() -> Result<()> { - let conf = Conf::builder() - .env() - .file("./settings.toml") - .file(shellexpand::tilde("~/twba/config.toml").into_owned()) - .file(std::env::var("TWBA_CONFIG").unwrap_or_else(|_| "~/twba/config.toml".to_string())) + let conf = twba_backup_config::get_default_builder() .load() .map_err(|e| SplitterError::LoadConfig(e.into()))?;