mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +01:00
fix(cli/agent start): Wait for applications to finish starting before returning
- Added a helper function `wait_until_conn_ready(port)` to wait for the benchmark and agent applications to finish starting - Improved the CLI's own logging (within the `agent start` command)
This commit is contained in:
25
cli.py
25
cli.py
@@ -274,12 +274,20 @@ def start(agent_name, no_setup):
|
|||||||
if os.path.exists(agent_dir) and os.path.isfile(run_command) and os.path.isfile(run_bench_command):
|
if os.path.exists(agent_dir) and os.path.isfile(run_command) and os.path.isfile(run_bench_command):
|
||||||
os.chdir(agent_dir)
|
os.chdir(agent_dir)
|
||||||
if not no_setup:
|
if not no_setup:
|
||||||
|
click.echo(f"⌛ Running setup for agent '{agent_name}'...")
|
||||||
setup_process = subprocess.Popen(["./setup"], cwd=agent_dir)
|
setup_process = subprocess.Popen(["./setup"], cwd=agent_dir)
|
||||||
setup_process.wait()
|
setup_process.wait()
|
||||||
|
click.echo()
|
||||||
|
|
||||||
subprocess.Popen(["./run_benchmark", "serve"], cwd=agent_dir)
|
subprocess.Popen(["./run_benchmark", "serve"], cwd=agent_dir)
|
||||||
click.echo(f"Benchmark Server starting please wait...")
|
click.echo("⌛ (Re)starting benchmark server...")
|
||||||
|
wait_until_conn_ready(8080)
|
||||||
|
click.echo()
|
||||||
|
|
||||||
subprocess.Popen(["./run"], cwd=agent_dir)
|
subprocess.Popen(["./run"], cwd=agent_dir)
|
||||||
click.echo(f"Agent '{agent_name}' starting please wait...")
|
click.echo(f"⌛ (Re)starting agent '{agent_name}'...")
|
||||||
|
wait_until_conn_ready(8000)
|
||||||
|
click.echo("✅ Agent application started and available on port 8000")
|
||||||
elif not os.path.exists(agent_dir):
|
elif not os.path.exists(agent_dir):
|
||||||
click.echo(
|
click.echo(
|
||||||
click.style(
|
click.style(
|
||||||
@@ -889,5 +897,18 @@ def update(agent_name, hash, branch):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_until_conn_ready(port: int = 8000):
|
||||||
|
"""Polls localhost:{port} until it is available for connections"""
|
||||||
|
import time
|
||||||
|
import socket
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(0.5)
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
if s.connect_ex(('localhost', port)) == 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user