From c25f2032d7b49b2ea6c0d16af4707295ef529d4e Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Wed, 2 Apr 2025 23:18:53 +0200 Subject: [PATCH] migrated to new version of sync script --- src/main.rs | 6 ++---- src/v1/mod.rs | 4 +--- src/v1/run/mod.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index abc4dd1..e8a62ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use dotenv::dotenv; use tokio::time::{sleep, Duration}; -use v1::{run_kcomebacks_command, run_likedsongs_command, run_projects_command}; +use v1::{run_sync_all_command}; use std::fs; pub mod v1; @@ -19,9 +19,7 @@ async fn periodic_script_runner() { loop { Logger::info("Running periodic scripts..."); // Run all Functions - let _ = run_kcomebacks_command(); - let _ = run_projects_command(); - let _ = run_likedsongs_command(); + let _ = run_sync_all_command(); // Sleep for 6 hours sleep(Duration::from_secs(6 * 60 * 60)).await; diff --git a/src/v1/mod.rs b/src/v1/mod.rs index ff4bf8f..199d74d 100644 --- a/src/v1/mod.rs +++ b/src/v1/mod.rs @@ -5,9 +5,7 @@ mod projects; mod run; pub use run::setup as run_setup; -pub use run::run_kcomebacks_command; -pub use run::run_projects_command; -pub use run::run_likedsongs_command; +pub use run::run_sync_all_command; pub use builtin::get_builtin_routes as get_v1_builtin_routes; pub use debug::get_debug_routes as get_v1_debug_routes; diff --git a/src/v1/run/mod.rs b/src/v1/run/mod.rs index 9861d53..4402b6b 100644 --- a/src/v1/run/mod.rs +++ b/src/v1/run/mod.rs @@ -26,6 +26,7 @@ pub fn get_run_routes() -> impl warp::Filter Result { } +async fn sync_all() -> Result { + // check if the local repository exists, if not, clone it + if !fs::metadata("./resources/turbo_octo_potato").is_ok() { + setup().unwrap(); + }; + + if let Err(err) = run_sync_all_command() { + // Handle the error here + eprintln!("Error: {}", err); + // Return an appropriate response or error + return Err(warp::reject::custom(InternalServerError)); + } + + Ok(warp::reply::json(&json!({"status": "syncing..."}))) + +} + pub fn setup() -> Result<(), git2::Error> { let repository_url = "https://github.com/JonasunderscoreJones/turbo-octo-potato.git"; let local_directory = "resources/turbo_octo_potato"; @@ -247,5 +265,20 @@ pub fn run_likedsongs_command() -> Result<(), std::io::Error> { // }); Logger::info("Syncing liked songs..."); + Ok(()) +} + +pub fn run_sync_all_command() -> Result<(), std::io::Error> { + task::spawn_blocking(move || { + let mut child = Command::new("python3") + .arg("script_interval_runner.py") + .current_dir("resources/turbo_octo_potato") + .stdout(Stdio::piped()) + .spawn() + .expect("failed to execute child"); + child.wait().unwrap(); + }); + Logger::info("Running all Sync Scripts..."); + Ok(()) } \ No newline at end of file