Spaces:
Build error
Build error
Dmitry Trifonov commited on
Commit ·
5a60604
1
Parent(s): 96fce2c
adjust to work with a new server
Browse files
fair.py
CHANGED
|
@@ -79,10 +79,10 @@ class FairApiClient:
|
|
| 79 |
|
| 80 |
return response['id'], response['pid']
|
| 81 |
|
| 82 |
-
def
|
| 83 |
-
url = f"{self.server_address}/jobs/{job_id}/
|
| 84 |
-
response = self.get(url=url)
|
| 85 |
-
return response
|
| 86 |
|
| 87 |
def get_cluster_summary(self):
|
| 88 |
url = f"{self.server_address}/nodes/summary"
|
|
@@ -143,15 +143,15 @@ class ServerNotReadyException(Exception):
|
|
| 143 |
pass
|
| 144 |
|
| 145 |
|
| 146 |
-
def wait_for_server(retries, timeout):
|
| 147 |
for i in range(retries):
|
| 148 |
try:
|
| 149 |
-
r = requests.get(ENDPOINT_ADDRESS)
|
| 150 |
r.raise_for_status()
|
| 151 |
return
|
| 152 |
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout):
|
| 153 |
logger.info("Server is not ready yet")
|
| 154 |
-
time.sleep(
|
| 155 |
else:
|
| 156 |
raise ServerNotReadyException("Failed to start the server")
|
| 157 |
|
|
@@ -172,12 +172,12 @@ def start_server():
|
|
| 172 |
|
| 173 |
logger.info(f"Job id: {job_id}, pid: {job_pid}")
|
| 174 |
|
| 175 |
-
|
| 176 |
-
logger.info(
|
| 177 |
|
| 178 |
-
while status != "Processing":
|
| 179 |
-
|
| 180 |
-
logger.info(
|
| 181 |
time.sleep(0.5)
|
| 182 |
|
| 183 |
# wait until the server is ready
|
|
@@ -186,7 +186,7 @@ def start_server():
|
|
| 186 |
|
| 187 |
def text_to_image(text):
|
| 188 |
try:
|
| 189 |
-
wait_for_server(retries=1, timeout=0.0)
|
| 190 |
except ServerNotReadyException:
|
| 191 |
start_server()
|
| 192 |
|
|
|
|
| 79 |
|
| 80 |
return response['id'], response['pid']
|
| 81 |
|
| 82 |
+
def get_job_info(self, job_id):
|
| 83 |
+
url = f"{self.server_address}/jobs/{job_id}/stat"
|
| 84 |
+
response = self.get(url=url).json()
|
| 85 |
+
return response
|
| 86 |
|
| 87 |
def get_cluster_summary(self):
|
| 88 |
url = f"{self.server_address}/nodes/summary"
|
|
|
|
| 143 |
pass
|
| 144 |
|
| 145 |
|
| 146 |
+
def wait_for_server(retries, timeout, delay=1.0):
|
| 147 |
for i in range(retries):
|
| 148 |
try:
|
| 149 |
+
r = requests.get(ENDPOINT_ADDRESS, timeout=timeout)
|
| 150 |
r.raise_for_status()
|
| 151 |
return
|
| 152 |
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout):
|
| 153 |
logger.info("Server is not ready yet")
|
| 154 |
+
time.sleep(delay)
|
| 155 |
else:
|
| 156 |
raise ServerNotReadyException("Failed to start the server")
|
| 157 |
|
|
|
|
| 172 |
|
| 173 |
logger.info(f"Job id: {job_id}, pid: {job_pid}")
|
| 174 |
|
| 175 |
+
info = client.get_job_info(job_id=job_id)
|
| 176 |
+
logger.info(info)
|
| 177 |
|
| 178 |
+
while info["status"] != "Processing":
|
| 179 |
+
info = client.get_job_info(job_id=job_id)
|
| 180 |
+
logger.info(info)
|
| 181 |
time.sleep(0.5)
|
| 182 |
|
| 183 |
# wait until the server is ready
|
|
|
|
| 186 |
|
| 187 |
def text_to_image(text):
|
| 188 |
try:
|
| 189 |
+
wait_for_server(retries=1, timeout=0.1, delay=0.0)
|
| 190 |
except ServerNotReadyException:
|
| 191 |
start_server()
|
| 192 |
|