database updater
This commit is contained in:
parent
2f535d8222
commit
cd9a466e9e
2 changed files with 34 additions and 57 deletions
|
|
@ -2243,57 +2243,29 @@ def get_version_info():
|
|||
return jsonify(version_data)
|
||||
|
||||
|
||||
def start_simple_background_monitor():
|
||||
"""Simple background thread that calls the existing status endpoint logic."""
|
||||
import time
|
||||
import threading
|
||||
|
||||
def simple_monitor():
|
||||
print("🔄 Simple background monitor started")
|
||||
|
||||
while True:
|
||||
try:
|
||||
# Check for pending matched downloads
|
||||
with matched_context_lock:
|
||||
pending_count = len(matched_downloads_context)
|
||||
pending_keys = list(matched_downloads_context.keys())
|
||||
|
||||
# Only process and log if there are pending downloads
|
||||
if pending_count > 0:
|
||||
print(f"🎯 Monitor: {pending_count} pending downloads: {[key.split('::')[-1] for key in pending_keys[:3]]}{'...' if len(pending_keys) > 3 else ''}")
|
||||
|
||||
# Just call the existing status endpoint logic directly
|
||||
with app.app_context():
|
||||
try:
|
||||
# Import what we need
|
||||
from flask import current_app
|
||||
with current_app.test_request_context():
|
||||
# Call the existing get_download_status function directly
|
||||
result = get_download_status()
|
||||
|
||||
# Check how many are left after processing
|
||||
with matched_context_lock:
|
||||
remaining_count = len(matched_downloads_context)
|
||||
|
||||
if remaining_count < pending_count:
|
||||
processed_count = pending_count - remaining_count
|
||||
print(f"✅ Status check processed {processed_count} downloads, {remaining_count} remaining")
|
||||
else:
|
||||
print(f"⏳ Status check completed, {remaining_count} still pending")
|
||||
|
||||
except Exception as status_error:
|
||||
print(f"❌ Status check error: {status_error}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
time.sleep(1) # Check every 1 second for maximum responsiveness
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Simple monitor error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
time.sleep(10)
|
||||
def _simple_monitor_task():
|
||||
"""The actual monitoring task that runs in the background thread."""
|
||||
print("🔄 Simple background monitor started")
|
||||
while True:
|
||||
try:
|
||||
with matched_context_lock:
|
||||
pending_count = len(matched_downloads_context)
|
||||
|
||||
if pending_count > 0:
|
||||
# Use app_context to safely call endpoint logic from a thread
|
||||
with app.app_context():
|
||||
get_download_status()
|
||||
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print(f"❌ Simple monitor error: {e}")
|
||||
time.sleep(10)
|
||||
|
||||
def start_simple_background_monitor():
|
||||
"""Starts the simple background monitor thread."""
|
||||
monitor_thread = threading.Thread(target=_simple_monitor_task)
|
||||
monitor_thread.daemon = True
|
||||
monitor_thread.start()
|
||||
|
||||
# ===============================
|
||||
# == DATABASE UPDATER API ==
|
||||
|
|
@ -2408,9 +2380,7 @@ def stop_database_update():
|
|||
|
||||
|
||||
|
||||
monitor_thread = threading.Thread(target=simple_monitor)
|
||||
monitor_thread.daemon = True
|
||||
monitor_thread.start()
|
||||
|
||||
|
||||
# --- Main Execution ---
|
||||
|
||||
|
|
|
|||
|
|
@ -3367,6 +3367,8 @@ function updateDbProgressUI(state) {
|
|||
|
||||
// --- Event Handlers ---
|
||||
|
||||
// --- Find and REPLACE the existing handleDbUpdateButtonClick function ---
|
||||
|
||||
async function handleDbUpdateButtonClick() {
|
||||
const button = document.getElementById('db-update-button');
|
||||
const currentAction = button.textContent;
|
||||
|
|
@ -3376,11 +3378,14 @@ async function handleDbUpdateButtonClick() {
|
|||
const isFullRefresh = refreshSelect.value === 'full';
|
||||
|
||||
if (isFullRefresh) {
|
||||
// Replicates the QMessageBox confirmation from the GUI
|
||||
const confirmed = confirm("⚠️ Full Refresh Warning!\n\nThis will clear and rebuild the database for the active server. It can take a long time. Are you sure you want to proceed?");
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
try {
|
||||
button.disabled = true;
|
||||
button.textContent = 'Starting...';
|
||||
const response = await fetch('/api/database/update', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
|
@ -3389,15 +3394,18 @@ async function handleDbUpdateButtonClick() {
|
|||
|
||||
if (response.ok) {
|
||||
showToast('Database update started!', 'success');
|
||||
// Start polling immediately
|
||||
stopDbUpdatePolling();
|
||||
dbUpdateStatusInterval = setInterval(checkAndUpdateDbProgress, 1000);
|
||||
// Start polling immediately to get live status
|
||||
checkAndUpdateDbProgress();
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
showToast(`Error: ${errorData.error}`, 'error');
|
||||
button.disabled = false;
|
||||
button.textContent = 'Update Database';
|
||||
}
|
||||
} catch (error) {
|
||||
showToast('Failed to start update process.', 'error');
|
||||
button.disabled = false;
|
||||
button.textContent = 'Update Database';
|
||||
}
|
||||
|
||||
} else { // "Stop Update"
|
||||
|
|
@ -3413,4 +3421,3 @@ async function handleDbUpdateButtonClick() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue