Commit
·
32262e9
1
Parent(s):
a58ec91
fix
Browse files- LoadBalancer.py +10 -36
LoadBalancer.py
CHANGED
@@ -18,8 +18,8 @@ CACHE_DIR = os.getenv("CACHE_DIR")
|
|
18 |
download_progress = {}
|
19 |
|
20 |
class LoadBalancer:
|
21 |
-
def __init__(self, cache_dir, index_file, token, repo, polling_interval=
|
22 |
-
self.version = "0.0.2.
|
23 |
self.instances = []
|
24 |
self.instances_health = {}
|
25 |
self.polling_interval = polling_interval
|
@@ -93,57 +93,31 @@ class LoadBalancer:
|
|
93 |
cache_size = report.get('cache_size')
|
94 |
|
95 |
logging.info(f"Processing report from {instance_url}")
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
temp_film_store_data = {}
|
101 |
-
temp_tv_store_data = {}
|
102 |
-
|
103 |
-
if os.path.exists(temp_film_store_path):
|
104 |
-
with open(temp_film_store_path, 'r') as json_file:
|
105 |
-
temp_film_store_data = json.load(json_file)
|
106 |
-
|
107 |
-
if os.path.exists(temp_tv_store_path):
|
108 |
-
with open(temp_tv_store_path, 'r') as json_file:
|
109 |
-
temp_tv_store_data = json.load(json_file)
|
110 |
|
111 |
# Process films
|
112 |
for title, path in film_store.items():
|
113 |
url = f"{instance_url}/api/film/{title.replace(' ', '%20')}"
|
114 |
-
|
115 |
|
|
|
116 |
# Process TV shows
|
117 |
for title, seasons in tv_store.items():
|
118 |
for season, episodes in seasons.items():
|
119 |
for episode, path in episodes.items():
|
120 |
url = f"{instance_url}/api/tv/{title.replace(' ', '%20')}/{season.replace(' ', '%20')}/{episode.replace(' ', '%20')}"
|
121 |
-
|
122 |
-
temp_tv_store_data[title] = {}
|
123 |
-
if season not in temp_tv_store_data[title]:
|
124 |
-
temp_tv_store_data[title][season] = {}
|
125 |
-
temp_tv_store_data[title][season][episode] = url
|
126 |
-
|
127 |
-
# Write temporary JSON files
|
128 |
-
with open(temp_film_store_path, 'w') as json_file:
|
129 |
-
json.dump(temp_film_store_data, json_file, indent=2)
|
130 |
-
|
131 |
-
with open(temp_tv_store_path, 'w') as json_file:
|
132 |
-
json.dump(temp_tv_store_data, json_file, indent=2)
|
133 |
-
|
134 |
-
logging.info("Temporary Film and TV Stores processed successfully.")
|
135 |
-
|
136 |
-
# Replace actual JSON files with temporary JSON files
|
137 |
-
os.replace(temp_film_store_path, self.FILM_STORE_JSON_PATH)
|
138 |
-
os.replace(temp_tv_store_path, self.TV_STORE_JSON_PATH)
|
139 |
|
|
|
140 |
self.update_instances_health(instance=instance_url, cache_size=cache_size)
|
141 |
|
142 |
def start_polling(self):
|
143 |
logging.info("Starting polling.")
|
144 |
while not self.stop_event.is_set():
|
145 |
self.get_reports()
|
146 |
-
|
147 |
logging.info("Polling stopped.")
|
148 |
|
149 |
def stop_polling(self):
|
|
|
18 |
download_progress = {}
|
19 |
|
20 |
class LoadBalancer:
|
21 |
+
def __init__(self, cache_dir, index_file, token, repo, polling_interval=1, max_retries=3, initial_delay=1):
|
22 |
+
self.version = "0.0.2.4 V Beta"
|
23 |
self.instances = []
|
24 |
self.instances_health = {}
|
25 |
self.polling_interval = polling_interval
|
|
|
93 |
cache_size = report.get('cache_size')
|
94 |
|
95 |
logging.info(f"Processing report from {instance_url}")
|
96 |
+
# logging.info(f"Film Store: {film_store}")
|
97 |
+
# logging.info(f"TV Store: {tv_store}")
|
98 |
+
# logging.info(f"Cache Size: {cache_size}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
# Process films
|
101 |
for title, path in film_store.items():
|
102 |
url = f"{instance_url}/api/film/{title.replace(' ', '%20')}"
|
103 |
+
self.update_film_store_json(title, url)
|
104 |
|
105 |
+
|
106 |
# Process TV shows
|
107 |
for title, seasons in tv_store.items():
|
108 |
for season, episodes in seasons.items():
|
109 |
for episode, path in episodes.items():
|
110 |
url = f"{instance_url}/api/tv/{title.replace(' ', '%20')}/{season.replace(' ', '%20')}/{episode.replace(' ', '%20')}"
|
111 |
+
self.update_tv_store_json(title, season, episode, url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
logging.info("Film and TV Stores processed successfully.")
|
114 |
self.update_instances_health(instance=instance_url, cache_size=cache_size)
|
115 |
|
116 |
def start_polling(self):
|
117 |
logging.info("Starting polling.")
|
118 |
while not self.stop_event.is_set():
|
119 |
self.get_reports()
|
120 |
+
time.sleep(self.polling_interval)
|
121 |
logging.info("Polling stopped.")
|
122 |
|
123 |
def stop_polling(self):
|