Skip to content

Commit

Permalink
Add retries to acquire_instance call, fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
emnigma committed Aug 7, 2023
1 parent 60a82e7 commit 622b374
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions VSharp.ML.AIAgent/connection/broker_conn/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

def acquire_instance() -> ServerInstanceInfo:
response, content = httplib2.Http().request(WebsocketSourceLinks.GET_WS)
if response.status != 200:
logging.error(f"{response.status} with {content=} on acuire_instance call")
raise RuntimeError(f"Not ok response: {response.status}")
aquired_instance = ServerInstanceInfo.from_json(json.loads(content.decode("utf-8")))
logging.info(f"acquired ws: {aquired_instance}")
return aquired_instance
Expand Down
2 changes: 1 addition & 1 deletion VSharp.ML.AIAgent/connection/broker_conn/socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def wait_for_connection(url: WSUrl):
ws = websocket.WebSocket()

max_retries = 60
retries_left = max_retries
retries_left = 60

while retries_left:
with suppress(ConnectionRefusedError, ConnectionResetError):
Expand Down
16 changes: 9 additions & 7 deletions VSharp.ML.AIAgent/launch_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

@routes.get("/get_ws")
async def dequeue_instance(request):
try:
server_info = SERVER_INSTANCES.get(timeout=0.1)
print(f"issued {server_info}")
return web.json_response(server_info.to_json())
except Empty as e:
print(f"{os.getpid()} tried to dequeue an empty queue. Waiting...")
return web.Response(text=str(e))
retry_count = 60
while retry_count:
try:
server_info = SERVER_INSTANCES.get(timeout=1)
print(f"issued {server_info}")
return web.json_response(server_info.to_json())
except Empty:
print(f"{os.getpid()} tried to dequeue an empty queue. Waiting...")
retry_count -= 1


@routes.post("/post_ws")
Expand Down

0 comments on commit 622b374

Please sign in to comment.