aboutsummaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorGravatar Reinier van der Leer <pwuts@agpt.co> 2024-02-15 11:26:26 +0100
committerGravatar Reinier van der Leer <pwuts@agpt.co> 2024-02-15 11:26:26 +0100
commit52b93dd84eae13432588346087c489f134e6f44f (patch)
tree9156e822542c0337368e5e24594edc7049913058 /cli.py
parentlint(agent): Fix telemetry.py linting error & formatting (diff)
downloadAuto-GPT-52b93dd84eae13432588346087c489f134e6f44f.tar.gz
Auto-GPT-52b93dd84eae13432588346087c489f134e6f44f.tar.bz2
Auto-GPT-52b93dd84eae13432588346087c489f134e6f44f.zip
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)
Diffstat (limited to 'cli.py')
-rw-r--r--cli.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/cli.py b/cli.py
index cd18982e9..3df045731 100644
--- a/cli.py
+++ b/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):
os.chdir(agent_dir)
if not no_setup:
+ click.echo(f"⌛ Running setup for agent '{agent_name}'...")
setup_process = subprocess.Popen(["./setup"], cwd=agent_dir)
setup_process.wait()
+ click.echo()
+
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)
- 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):
click.echo(
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__":
cli()