fix wishlist modal not auto restarting after initial run.

This commit is contained in:
Broque Thomas 2025-09-23 08:44:47 -07:00
parent a053ed22a3
commit 35f4b25bad
2 changed files with 24 additions and 18 deletions

View file

@ -5795,11 +5795,7 @@ def start_wishlist_auto_processing():
"""Start automatic wishlist processing with 1-minute initial delay.""" """Start automatic wishlist processing with 1-minute initial delay."""
global wishlist_auto_timer global wishlist_auto_timer
# Skip if this is Flask's debug reloader process print("🚀 [Auto-Wishlist] Initializing automatic wishlist processing...")
import os
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
print("🔄 Skipping auto-processing start in Flask debug reloader")
return
with wishlist_timer_lock: with wishlist_timer_lock:
# Stop any existing timer to prevent duplicates # Stop any existing timer to prevent duplicates
@ -5810,6 +5806,7 @@ def start_wishlist_auto_processing():
wishlist_auto_timer = threading.Timer(60.0, _process_wishlist_automatically) # 1 minute wishlist_auto_timer = threading.Timer(60.0, _process_wishlist_automatically) # 1 minute
wishlist_auto_timer.daemon = True wishlist_auto_timer.daemon = True
wishlist_auto_timer.start() wishlist_auto_timer.start()
print(f"✅ [Debug] Timer started successfully - will trigger in 60 seconds")
def stop_wishlist_auto_processing(): def stop_wishlist_auto_processing():
"""Stop automatic wishlist processing and cleanup timer.""" """Stop automatic wishlist processing and cleanup timer."""
@ -5824,12 +5821,12 @@ def stop_wishlist_auto_processing():
wishlist_auto_processing = False wishlist_auto_processing = False
def schedule_next_wishlist_processing(): def schedule_next_wishlist_processing():
"""Schedule next automatic wishlist processing in 10 minutes.""" """Schedule next automatic wishlist processing in 30 minutes."""
global wishlist_auto_timer global wishlist_auto_timer
with wishlist_timer_lock: with wishlist_timer_lock:
print("⏰ Scheduling next automatic wishlist processing in 10 minutes") print("⏰ Scheduling next automatic wishlist processing in 30 minutes")
wishlist_auto_timer = threading.Timer(600.0, _process_wishlist_automatically) # 10 minutes wishlist_auto_timer = threading.Timer(1800.0, _process_wishlist_automatically) # 30 minutes (1800 seconds)
wishlist_auto_timer.daemon = True wishlist_auto_timer.daemon = True
wishlist_auto_timer.start() wishlist_auto_timer.start()
@ -5837,7 +5834,7 @@ def _process_wishlist_automatically():
"""Main automatic processing logic that runs in background thread.""" """Main automatic processing logic that runs in background thread."""
global wishlist_auto_processing global wishlist_auto_processing
print("🤖 Starting automatic wishlist processing...") print("🤖 [Auto-Wishlist] Timer triggered - starting automatic wishlist processing...")
try: try:
with wishlist_timer_lock: with wishlist_timer_lock:
@ -5864,14 +5861,15 @@ def _process_wishlist_automatically():
# Check if wishlist has tracks # Check if wishlist has tracks
count = wishlist_service.get_wishlist_count() count = wishlist_service.get_wishlist_count()
print(f"🔍 [Auto-Wishlist] Wishlist count check: {count} tracks found")
if count == 0: if count == 0:
print(" No tracks in wishlist for auto-processing.") print(" [Auto-Wishlist] No tracks in wishlist for auto-processing.")
with wishlist_timer_lock: with wishlist_timer_lock:
wishlist_auto_processing = False wishlist_auto_processing = False
schedule_next_wishlist_processing() schedule_next_wishlist_processing()
return return
print(f"🎵 Found {count} tracks in wishlist, starting automatic processing...") print(f"🎵 [Auto-Wishlist] Found {count} tracks in wishlist, starting automatic processing...")
# Check if wishlist processing is already active # Check if wishlist processing is already active
playlist_id = "wishlist" playlist_id = "wishlist"
@ -6789,7 +6787,7 @@ def _process_failed_tracks_to_wishlist_exact_with_auto_completion(batch_id):
wishlist_auto_processing = False wishlist_auto_processing = False
# Schedule next automatic processing cycle # Schedule next automatic processing cycle
print("⏰ [Auto-Wishlist] Scheduling next automatic cycle in 10 minutes") print("⏰ [Auto-Wishlist] Scheduling next automatic cycle in 30 minutes")
schedule_next_wishlist_processing() schedule_next_wishlist_processing()
return completion_summary return completion_summary
@ -6804,7 +6802,7 @@ def _process_failed_tracks_to_wishlist_exact_with_auto_completion(batch_id):
wishlist_auto_processing = False wishlist_auto_processing = False
# Schedule next cycle even after error to maintain continuity # Schedule next cycle even after error to maintain continuity
print("⏰ [Auto-Wishlist] Scheduling next cycle after error (10 minutes)") print("⏰ [Auto-Wishlist] Scheduling next cycle after error (30 minutes)")
schedule_next_wishlist_processing() schedule_next_wishlist_processing()
return {'tracks_added': 0, 'errors': 1, 'total_failed': 0} return {'tracks_added': 0, 'errors': 1, 'total_failed': 0}

View file

@ -4200,6 +4200,14 @@ function processModalStatusUpdate(playlistId, data) {
const completionMessage = `Download complete! ${completedCount} downloaded, ${failedOrCancelledCount} failed.`; const completionMessage = `Download complete! ${completedCount} downloaded, ${failedOrCancelledCount} failed.`;
showToast(completionMessage, 'success'); showToast(completionMessage, 'success');
// Auto-close wishlist modal when completed (for auto-processing)
if (playlistId === 'wishlist') {
console.log('🔄 [Auto-Wishlist] Auto-closing completed wishlist modal to enable next cycle');
setTimeout(() => {
closeDownloadMissingModal(playlistId);
}, 3000); // 3-second delay to show completion message
}
// Check if any other processes still need polling // Check if any other processes still need polling
checkAndCleanupGlobalPolling(); checkAndCleanupGlobalPolling();