Spaces:
Sleeping
Sleeping
Commit
·
d93fcf9
1
Parent(s):
f3784c6
unstable fix
Browse files- LoadBalancer.py +6 -13
LoadBalancer.py
CHANGED
|
@@ -4,7 +4,6 @@ import re
|
|
| 4 |
import urllib.parse
|
| 5 |
from tvdb import fetch_and_cache_json
|
| 6 |
from threading import Event, Thread
|
| 7 |
-
from fastapi import BackgroundTasks
|
| 8 |
import asyncio
|
| 9 |
import time
|
| 10 |
import logging
|
|
@@ -37,7 +36,7 @@ class LoadBalancer:
|
|
| 37 |
|
| 38 |
# Initialize file structure and prefetching
|
| 39 |
self.file_structure = indexer()
|
| 40 |
-
self.start_prefetching()
|
| 41 |
|
| 42 |
# Start polling and file checking in separate threads
|
| 43 |
polling_thread = Thread(target=self.start_polling)
|
|
@@ -49,13 +48,9 @@ class LoadBalancer:
|
|
| 49 |
content_check_thread.daemon = True
|
| 50 |
content_check_thread.start()
|
| 51 |
|
| 52 |
-
def start_prefetching(self):
|
| 53 |
-
"""Start the metadata prefetching
|
| 54 |
-
|
| 55 |
-
background_tasks = BackgroundTasks()
|
| 56 |
-
# Add the prefetch_metadata coroutine to the background tasks
|
| 57 |
-
background_tasks.add_task(self.prefetch_metadata)
|
| 58 |
-
return background_tasks
|
| 59 |
|
| 60 |
async def prefetch_metadata(self):
|
| 61 |
"""Prefetch metadata for all items in the file structure."""
|
|
@@ -95,10 +90,8 @@ class LoadBalancer:
|
|
| 95 |
time.sleep(120) # Wait for 2 minutes
|
| 96 |
current_file_structure = indexer()
|
| 97 |
if current_file_structure != self.previous_file_structure:
|
| 98 |
-
# Trigger prefetching
|
| 99 |
-
|
| 100 |
-
# Here you need to integrate background_tasks with FastAPI
|
| 101 |
-
# For example, you might need to pass it to your FastAPI route handler or another component
|
| 102 |
self.previous_file_structure = current_file_structure
|
| 103 |
else:
|
| 104 |
logging.info("No new content detected.")
|
|
|
|
| 4 |
import urllib.parse
|
| 5 |
from tvdb import fetch_and_cache_json
|
| 6 |
from threading import Event, Thread
|
|
|
|
| 7 |
import asyncio
|
| 8 |
import time
|
| 9 |
import logging
|
|
|
|
| 36 |
|
| 37 |
# Initialize file structure and prefetching
|
| 38 |
self.file_structure = indexer()
|
| 39 |
+
asyncio.run(self.start_prefetching()) # Run the async method directly
|
| 40 |
|
| 41 |
# Start polling and file checking in separate threads
|
| 42 |
polling_thread = Thread(target=self.start_polling)
|
|
|
|
| 48 |
content_check_thread.daemon = True
|
| 49 |
content_check_thread.start()
|
| 50 |
|
| 51 |
+
async def start_prefetching(self):
|
| 52 |
+
"""Start the metadata prefetching."""
|
| 53 |
+
await self.prefetch_metadata()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
async def prefetch_metadata(self):
|
| 56 |
"""Prefetch metadata for all items in the file structure."""
|
|
|
|
| 90 |
time.sleep(120) # Wait for 2 minutes
|
| 91 |
current_file_structure = indexer()
|
| 92 |
if current_file_structure != self.previous_file_structure:
|
| 93 |
+
# Trigger prefetching directly in an asyncio context
|
| 94 |
+
asyncio.run(self.start_prefetching())
|
|
|
|
|
|
|
| 95 |
self.previous_file_structure = current_file_structure
|
| 96 |
else:
|
| 97 |
logging.info("No new content detected.")
|