mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-22 16:59:17 +02:00
migrated to new version of sync script
This commit is contained in:
parent
9ef64b5b82
commit
c25f2032d7
3 changed files with 36 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use tokio::time::{sleep, Duration};
|
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;
|
use std::fs;
|
||||||
|
|
||||||
pub mod v1;
|
pub mod v1;
|
||||||
|
@ -19,9 +19,7 @@ async fn periodic_script_runner() {
|
||||||
loop {
|
loop {
|
||||||
Logger::info("Running periodic scripts...");
|
Logger::info("Running periodic scripts...");
|
||||||
// Run all Functions
|
// Run all Functions
|
||||||
let _ = run_kcomebacks_command();
|
let _ = run_sync_all_command();
|
||||||
let _ = run_projects_command();
|
|
||||||
let _ = run_likedsongs_command();
|
|
||||||
|
|
||||||
// Sleep for 6 hours
|
// Sleep for 6 hours
|
||||||
sleep(Duration::from_secs(6 * 60 * 60)).await;
|
sleep(Duration::from_secs(6 * 60 * 60)).await;
|
||||||
|
|
|
@ -5,9 +5,7 @@ mod projects;
|
||||||
mod run;
|
mod run;
|
||||||
|
|
||||||
pub use run::setup as run_setup;
|
pub use run::setup as run_setup;
|
||||||
pub use run::run_kcomebacks_command;
|
pub use run::run_sync_all_command;
|
||||||
pub use run::run_projects_command;
|
|
||||||
pub use run::run_likedsongs_command;
|
|
||||||
|
|
||||||
pub use builtin::get_builtin_routes as get_v1_builtin_routes;
|
pub use builtin::get_builtin_routes as get_v1_builtin_routes;
|
||||||
pub use debug::get_debug_routes as get_v1_debug_routes;
|
pub use debug::get_debug_routes as get_v1_debug_routes;
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub fn get_run_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error =
|
||||||
.or(warp::path("projects").and_then(update_projects))
|
.or(warp::path("projects").and_then(update_projects))
|
||||||
.or(warp::path("makediscography").map(||"Not implemented yet"))
|
.or(warp::path("makediscography").map(||"Not implemented yet"))
|
||||||
.or(warp::path("synclikedsongs").and_then(sync_liked_songs))
|
.or(warp::path("synclikedsongs").and_then(sync_liked_songs))
|
||||||
|
.or(warp::path("sync_all").and_then(sync_all))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +81,23 @@ async fn sync_liked_songs() -> Result<impl warp::Reply, warp::Rejection> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn sync_all() -> Result<impl warp::Reply, warp::Rejection> {
|
||||||
|
// 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> {
|
pub fn setup() -> Result<(), git2::Error> {
|
||||||
let repository_url = "https://github.com/JonasunderscoreJones/turbo-octo-potato.git";
|
let repository_url = "https://github.com/JonasunderscoreJones/turbo-octo-potato.git";
|
||||||
let local_directory = "resources/turbo_octo_potato";
|
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...");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue