Spaces:
Build error
Build error
Commit ·
204e87b
1
Parent(s): 1b04383
0.0.2.2 V Beta
Browse files- LoadBalancer.py +9 -1
- app.py +4 -0
LoadBalancer.py
CHANGED
|
@@ -19,8 +19,9 @@ download_progress = {}
|
|
| 19 |
|
| 20 |
class LoadBalancer:
|
| 21 |
def __init__(self, cache_dir, index_file, token, repo, polling_interval=10, max_retries=3, initial_delay=1):
|
| 22 |
-
self.version = "0.0.2.
|
| 23 |
self.instances = []
|
|
|
|
| 24 |
self.polling_interval = polling_interval
|
| 25 |
self.max_retries = max_retries
|
| 26 |
self.initial_delay = initial_delay
|
|
@@ -106,6 +107,7 @@ class LoadBalancer:
|
|
| 106 |
self.update_tv_store_json(title, season, episode, url)
|
| 107 |
|
| 108 |
logging.info("Film and TV Stores processed successfully.")
|
|
|
|
| 109 |
|
| 110 |
def start_polling(self):
|
| 111 |
logging.info("Starting polling.")
|
|
@@ -222,7 +224,13 @@ class LoadBalancer:
|
|
| 222 |
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
| 223 |
return re.match(regex, url) is not None
|
| 224 |
|
|
|
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
def load_json(self, file_path):
|
| 227 |
"""Load JSON data from a file."""
|
| 228 |
with open(file_path, 'r') as file:
|
|
|
|
| 19 |
|
| 20 |
class LoadBalancer:
|
| 21 |
def __init__(self, cache_dir, index_file, token, repo, polling_interval=10, max_retries=3, initial_delay=1):
|
| 22 |
+
self.version = "0.0.2.2 V Beta"
|
| 23 |
self.instances = []
|
| 24 |
+
self.instances_health = {}
|
| 25 |
self.polling_interval = polling_interval
|
| 26 |
self.max_retries = max_retries
|
| 27 |
self.initial_delay = initial_delay
|
|
|
|
| 107 |
self.update_tv_store_json(title, season, episode, url)
|
| 108 |
|
| 109 |
logging.info("Film and TV Stores processed successfully.")
|
| 110 |
+
self.update_instances_health(instance=instance_url, cache_size=cache_size)
|
| 111 |
|
| 112 |
def start_polling(self):
|
| 113 |
logging.info("Starting polling.")
|
|
|
|
| 224 |
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
| 225 |
return re.match(regex, url) is not None
|
| 226 |
|
| 227 |
+
#################################################################
|
| 228 |
|
| 229 |
+
def update_instances_health(self, instance, cache_size):
|
| 230 |
+
self.instances_health[instance] = cache_size
|
| 231 |
+
logging.info(f"Updated instance {instance} with cache size {cache_size}")
|
| 232 |
+
|
| 233 |
+
#################################################################
|
| 234 |
def load_json(self, file_path):
|
| 235 |
"""Load JSON data from a file."""
|
| 236 |
with open(file_path, 'r') as file:
|
app.py
CHANGED
|
@@ -242,6 +242,10 @@ def register_instance():
|
|
| 242 |
def get_instances():
|
| 243 |
return load_balancer.instances
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
#############################################################
|
| 246 |
# Routes
|
| 247 |
@app.route('/')
|
|
|
|
| 242 |
def get_instances():
|
| 243 |
return load_balancer.instances
|
| 244 |
|
| 245 |
+
@app.route('/api/instances/health',methods=["GET"])
|
| 246 |
+
def get_instances_health():
|
| 247 |
+
return load_balancer.instances_health
|
| 248 |
+
|
| 249 |
#############################################################
|
| 250 |
# Routes
|
| 251 |
@app.route('/')
|