Skip to content

Commit 08c5765

Browse files
committed
Add function to refresh sponsors from manifest.json on startup
- Implemented `refresh_sponsors_on_startup` to load sponsors from manifest.json and update the database. - Added error handling and logging for missing manifest file and empty sponsors list. - Integrated the refresh function into the main application startup process.
1 parent 9ae58f0 commit 08c5765

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@ def __init__(self, *args, **kwargs):
151151
waitress_server = None
152152
shutdown_requested = threading.Event()
153153

154+
def refresh_sponsors_on_startup():
155+
"""Refresh sponsors database from manifest.json on startup"""
156+
import os
157+
import json
158+
159+
try:
160+
# Get database instance
161+
from src.primary.utils.database import get_database
162+
db = get_database()
163+
164+
# Path to manifest.json
165+
manifest_path = os.path.join(os.path.dirname(__file__), 'manifest.json')
166+
167+
if os.path.exists(manifest_path):
168+
with open(manifest_path, 'r') as f:
169+
manifest_data = json.load(f)
170+
171+
sponsors_list = manifest_data.get('sponsors', [])
172+
if sponsors_list:
173+
# Clear existing sponsors and save new ones
174+
db.save_sponsors(sponsors_list)
175+
huntarr_logger.debug(f"Refreshed {len(sponsors_list)} sponsors from manifest.json")
176+
else:
177+
huntarr_logger.warning("No sponsors found in manifest.json")
178+
else:
179+
huntarr_logger.warning(f"manifest.json not found at {manifest_path}")
180+
181+
except Exception as e:
182+
huntarr_logger.error(f"Error refreshing sponsors on startup: {e}")
183+
raise
184+
154185
def run_background_tasks():
155186
"""Runs the Huntarr background processing."""
156187
bg_logger = get_logger("HuntarrBackground") # Use app's logger
@@ -320,6 +351,13 @@ def main():
320351
except Exception as migration_error:
321352
huntarr_logger.warning(f"History migration completed with warnings: {migration_error}")
322353

354+
# Refresh sponsors from manifest.json on startup
355+
try:
356+
refresh_sponsors_on_startup()
357+
huntarr_logger.info("Sponsors database refreshed from manifest.json")
358+
except Exception as sponsor_error:
359+
huntarr_logger.warning(f"Failed to refresh sponsors on startup: {sponsor_error}")
360+
323361
except Exception as e:
324362
huntarr_logger.error(f"Failed to initialize databases: {e}")
325363
huntarr_logger.error("Application may not function correctly without database")

0 commit comments

Comments
 (0)