Added wait for service

This commit is contained in:
Saifeddine ALOUI 2024-01-10 22:08:58 +01:00
parent 25334549ec
commit d440b3db8a

View File

@ -96,3 +96,26 @@ class Service:
# Wait until the service is available at http://127.0.0.1:7860/
self.wait_for_service(max_retries=wait_max_retries)
def wait_for_service(self, max_retries = 150, show_warning=True):
url = f"{self.xtts_base_url}/languages"
# Adjust this value as needed
retries = 0
while retries < max_retries or max_retries<0:
try:
response = requests.get(url)
if response.status_code == 200:
print("Service is available.")
if self.app is not None:
self.app.success("Ollama Service is now available.")
return True
except requests.exceptions.RequestException:
pass
retries += 1
time.sleep(1)
if show_warning:
print("Service did not become available within the given time.")
if self.app is not None:
self.app.error("Ollama Service did not become available within the given time.")
return False