Spaces:
Sleeping
Sleeping
Commit
·
4c930f9
1
Parent(s):
62cd5c9
improve routes
Browse files- LoadBalancer.py +0 -4
- app.py +13 -5
LoadBalancer.py
CHANGED
|
@@ -117,14 +117,11 @@ class LoadBalancer:
|
|
| 117 |
"""Start the metadata prefetching in a separate thread."""
|
| 118 |
self.prefetch_metadata()
|
| 119 |
|
| 120 |
-
#################################################################
|
| 121 |
-
|
| 122 |
def update_instances_health(self, instance, cache_size):
|
| 123 |
self.instances_health[instance] = {"used":cache_size["cache_size"],
|
| 124 |
"total": "50 GB"}
|
| 125 |
logging.info(f"Updated instance {instance} with cache size {cache_size}")
|
| 126 |
|
| 127 |
-
|
| 128 |
def download_film_to_best_instance(self, title):
|
| 129 |
"""
|
| 130 |
Downloads a film to the first instance that has more free space on the self.instance_health list variable.
|
|
@@ -211,7 +208,6 @@ class LoadBalancer:
|
|
| 211 |
logging.error("No suitable instance found for downloading the film.")
|
| 212 |
return {"error": "No suitable instance found for downloading the film."}
|
| 213 |
|
| 214 |
-
#################################################################
|
| 215 |
def find_movie_path(self, title):
|
| 216 |
"""Find the path of the movie in the JSON data based on the title."""
|
| 217 |
for directory in self.file_structure:
|
|
|
|
| 117 |
"""Start the metadata prefetching in a separate thread."""
|
| 118 |
self.prefetch_metadata()
|
| 119 |
|
|
|
|
|
|
|
| 120 |
def update_instances_health(self, instance, cache_size):
|
| 121 |
self.instances_health[instance] = {"used":cache_size["cache_size"],
|
| 122 |
"total": "50 GB"}
|
| 123 |
logging.info(f"Updated instance {instance} with cache size {cache_size}")
|
| 124 |
|
|
|
|
| 125 |
def download_film_to_best_instance(self, title):
|
| 126 |
"""
|
| 127 |
Downloads a film to the first instance that has more free space on the self.instance_health list variable.
|
|
|
|
| 208 |
logging.error("No suitable instance found for downloading the film.")
|
| 209 |
return {"error": "No suitable instance found for downloading the film."}
|
| 210 |
|
|
|
|
| 211 |
def find_movie_path(self, title):
|
| 212 |
"""Find the path of the movie in the JSON data based on the title."""
|
| 213 |
for directory in self.file_structure:
|
app.py
CHANGED
|
@@ -23,10 +23,18 @@ async def register_instance():
|
|
| 23 |
async def get_file_structure():
|
| 24 |
return load_balancer.file_structure
|
| 25 |
|
| 26 |
-
@app.get("/api/get/film/
|
| 27 |
-
async def
|
| 28 |
return load_balancer.FILM_STORE
|
| 29 |
|
| 30 |
-
@app.get("/api/get/tv/
|
| 31 |
-
async def
|
| 32 |
-
return load_balancer.TV_STORE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
async def get_file_structure():
|
| 24 |
return load_balancer.file_structure
|
| 25 |
|
| 26 |
+
@app.get("/api/get/film/store")
|
| 27 |
+
async def get_film_store():
|
| 28 |
return load_balancer.FILM_STORE
|
| 29 |
|
| 30 |
+
@app.get("/api/get/tv/store")
|
| 31 |
+
async def get_tv_store():
|
| 32 |
+
return load_balancer.TV_STORE
|
| 33 |
+
|
| 34 |
+
@app.get("/api/film/all")
|
| 35 |
+
async def get_all_films_api():
|
| 36 |
+
return load_balancer.get_all_films()
|
| 37 |
+
|
| 38 |
+
@app.get("/api/tv/all")
|
| 39 |
+
async def get_all_tvshows_api():
|
| 40 |
+
return load_balancer.get_all_tv_shows()
|