From 4008b4d8384f34a8cf383ab9fb4a1916ca4fb666 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Fri, 20 Mar 2026 16:28:15 -0400 Subject: [PATCH] Added the watch and scheduler systems --- Cargo.lock | 1 + shanty-config/src/lib.rs | 40 ++++++++++++++++++++++++++++++ shanty-config/tests/integration.rs | 2 +- shanty-db | 2 +- shanty-tag | 2 +- shanty-watch | 2 +- shanty-web | 2 +- src/main.rs | 8 ++++++ 8 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f86e85..5447144 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3304,6 +3304,7 @@ dependencies = [ "sea-orm", "serde", "serde_json", + "shanty-data", "shanty-db", "shanty-tag", "strsim", diff --git a/shanty-config/src/lib.rs b/shanty-config/src/lib.rs index 9a2ae88..353f0fb 100644 --- a/shanty-config/src/lib.rs +++ b/shanty-config/src/lib.rs @@ -35,6 +35,9 @@ pub struct AppConfig { #[serde(default)] pub metadata: MetadataConfig, + + #[serde(default)] + pub scheduling: SchedulingConfig, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -130,6 +133,36 @@ pub struct MetadataConfig { pub fanart_api_key: Option, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SchedulingConfig { + /// Enable automatic pipeline runs. + #[serde(default)] + pub pipeline_enabled: bool, + + /// Hours between pipeline runs (after previous completion). + #[serde(default = "default_pipeline_interval_hours")] + pub pipeline_interval_hours: u32, + + /// Enable automatic new release checking for monitored artists. + #[serde(default)] + pub monitor_enabled: bool, + + /// Hours between monitor checks. + #[serde(default = "default_monitor_interval_hours")] + pub monitor_interval_hours: u32, +} + +impl Default for SchedulingConfig { + fn default() -> Self { + Self { + pipeline_enabled: true, + pipeline_interval_hours: default_pipeline_interval_hours(), + monitor_enabled: true, + monitor_interval_hours: default_monitor_interval_hours(), + } + } +} + // --- Defaults --- impl Default for AppConfig { @@ -145,6 +178,7 @@ impl Default for AppConfig { download: DownloadConfig::default(), indexing: IndexingConfig::default(), metadata: MetadataConfig::default(), + scheduling: SchedulingConfig::default(), } } } @@ -272,6 +306,12 @@ fn default_lyrics_source() -> String { fn default_cover_art_source() -> String { "coverartarchive".to_string() } +fn default_pipeline_interval_hours() -> u32 { + 3 +} +fn default_monitor_interval_hours() -> u32 { + 12 +} fn default_cookie_refresh_hours() -> u32 { 6 } diff --git a/shanty-config/tests/integration.rs b/shanty-config/tests/integration.rs index e294a59..33ccf78 100644 --- a/shanty-config/tests/integration.rs +++ b/shanty-config/tests/integration.rs @@ -10,7 +10,7 @@ fn test_default_config() { assert!(!config.tagging.auto_tag); assert_eq!(config.download.format, "opus"); assert_eq!(config.download.search_source, "ytmusic"); - assert_eq!(config.download.rate_limit, 450); + assert_eq!(config.download.rate_limit, 250); assert_eq!(config.download.rate_limit_auth, 1800); assert_eq!(config.indexing.concurrency, 4); assert!(config.allowed_secondary_types.is_empty()); diff --git a/shanty-db b/shanty-db index 9917ee9..8a1435d 160000 --- a/shanty-db +++ b/shanty-db @@ -1 +1 @@ -Subproject commit 9917ee981dd5f8196c4eb68d30075f6474f6efd6 +Subproject commit 8a1435d9e94135617bd55c8bbb74d21a1622cc88 diff --git a/shanty-tag b/shanty-tag index 2280e95..e5b3fc3 160000 --- a/shanty-tag +++ b/shanty-tag @@ -1 +1 @@ -Subproject commit 2280e9564d7241f5053d73d2cf71de405bdc8d21 +Subproject commit e5b3fc3fe33c16954bd5c478ea27b6cac9c66665 diff --git a/shanty-watch b/shanty-watch index 15a4efe..85e2467 160000 --- a/shanty-watch +++ b/shanty-watch @@ -1 +1 @@ -Subproject commit 15a4efe1e974264948a459c7a116d8e3cfdfdffc +Subproject commit 85e24671a33dc86989bbf9db3135d172e31fa3e7 diff --git a/shanty-web b/shanty-web index eaaff5f..9d6c0e3 160000 --- a/shanty-web +++ b/shanty-web @@ -1 +1 @@ -Subproject commit eaaff5f98f8a85ff2572727fc2799ad52bb71520 +Subproject commit 9d6c0e31c1f14b73dc70b9016fecd2b37e2aa30f diff --git a/src/main.rs b/src/main.rs index 4e80f98..334a6f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,11 +74,19 @@ async fn main() -> anyhow::Result<()> { config_path, tasks: TaskManager::new(), firefox_login: tokio::sync::Mutex::new(None), + scheduler: tokio::sync::Mutex::new(shanty_web::state::SchedulerInfo { + next_pipeline: None, + next_monitor: None, + }), }); // Start background cookie refresh task shanty_web::cookie_refresh::spawn(state.config.clone()); + // Start pipeline and monitor schedulers + shanty_web::pipeline_scheduler::spawn(state.clone()); + shanty_web::monitor::spawn(state.clone()); + // Resolve static files directory let static_dir = std::env::current_exe() .ok()