Spaces:
Sleeping
Sleeping
Commit
·
5517352
1
Parent(s):
54517df
revert
Browse files- LoadBalancer.py +7 -7
LoadBalancer.py
CHANGED
|
@@ -14,7 +14,7 @@ CACHE_DIR = os.getenv("CACHE_DIR")
|
|
| 14 |
|
| 15 |
class LoadBalancer:
|
| 16 |
def __init__(self, cache_dir, token, repo, polling_interval=4, max_retries=3, initial_delay=1):
|
| 17 |
-
self.version = "0.0.0.
|
| 18 |
self.instances = []
|
| 19 |
self.instances_health = {}
|
| 20 |
self.polling_interval = polling_interval
|
|
@@ -34,8 +34,9 @@ class LoadBalancer:
|
|
| 34 |
if not os.path.exists(self.CACHE_DIR):
|
| 35 |
os.makedirs(self.CACHE_DIR)
|
| 36 |
|
| 37 |
-
# Initialize file structure
|
| 38 |
self.file_structure = indexer()
|
|
|
|
| 39 |
|
| 40 |
# Start polling and file checking in separate threads
|
| 41 |
polling_thread = Thread(target=self.start_polling)
|
|
@@ -47,9 +48,9 @@ class LoadBalancer:
|
|
| 47 |
content_check_thread.daemon = True
|
| 48 |
content_check_thread.start()
|
| 49 |
|
| 50 |
-
|
| 51 |
-
"""Start the metadata prefetching."""
|
| 52 |
-
|
| 53 |
|
| 54 |
async def prefetch_metadata(self):
|
| 55 |
"""Prefetch metadata for all items in the file structure."""
|
|
@@ -89,8 +90,7 @@ class LoadBalancer:
|
|
| 89 |
time.sleep(120) # Wait for 2 minutes
|
| 90 |
current_file_structure = indexer()
|
| 91 |
if current_file_structure != self.previous_file_structure:
|
| 92 |
-
|
| 93 |
-
asyncio.get_event_loop().create_task(self.start_prefetching())
|
| 94 |
self.previous_file_structure = current_file_structure
|
| 95 |
else:
|
| 96 |
logging.info("No new content detected.")
|
|
|
|
| 14 |
|
| 15 |
class LoadBalancer:
|
| 16 |
def __init__(self, cache_dir, token, repo, polling_interval=4, max_retries=3, initial_delay=1):
|
| 17 |
+
self.version = "0.0.0.2 Alpha"
|
| 18 |
self.instances = []
|
| 19 |
self.instances_health = {}
|
| 20 |
self.polling_interval = polling_interval
|
|
|
|
| 34 |
if not os.path.exists(self.CACHE_DIR):
|
| 35 |
os.makedirs(self.CACHE_DIR)
|
| 36 |
|
| 37 |
+
# Initialize file structure and prefetching
|
| 38 |
self.file_structure = indexer()
|
| 39 |
+
self.start_prefetching()
|
| 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 |
+
def start_prefetching(self):
|
| 52 |
+
"""Start the metadata prefetching in the FastAPI event loop."""
|
| 53 |
+
asyncio.create_task(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 |
+
self.start_prefetching()
|
|
|
|
| 94 |
self.previous_file_structure = current_file_structure
|
| 95 |
else:
|
| 96 |
logging.info("No new content detected.")
|