argos/argos/commands.py

58 lines
1.5 KiB
Python

import asyncio
import subprocess
import click
from argos import logging
from argos.agent import run_agent
@click.group()
def cli():
pass
@cli.command()
@click.argument("server")
@click.argument("auth")
@click.option(
"--max-tasks",
default=10,
help="Number of concurrent tasks this agent can run",
)
@click.option(
"--wait-time",
default=10,
help="Waiting time between two polls on the server (seconds)",
)
@click.option(
"--log-level",
default="INFO",
type=click.Choice(logging.LOG_LEVELS, case_sensitive=False),
)
def agent(server, auth, max_tasks, wait_time, log_level):
"""Get and run tasks to the provided server. Will wait for new tasks.
Usage: argos agent https://argos.server "auth-token-here"
"""
logging.set_log_level(log_level)
asyncio.run(run_agent(server, auth, max_tasks, wait_time))
@cli.command()
@click.option("--host", default="127.0.0.1", help="Host to bind")
@click.option("--port", default=8000, type=int, help="Port to bind")
@click.option("--reload", is_flag=True, help="Enable hot reloading")
@click.option("--log-config", help="Path to the logging configuration file")
def server(host, port, reload, log_config):
"""Starts the server."""
command = ["uvicorn", "argos.server:app", "--host", host, "--port", str(port)]
if reload:
command.append("--reload")
if log_config:
command.extend(["--log-config", log_config])
subprocess.run(command)
if __name__ == "__main__":
cli()