— Config file option on almost all server commands

This commit is contained in:
Luc Didry 2024-04-11 09:12:01 +02:00
parent 5237351492
commit 8b3a8dd153
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C
2 changed files with 37 additions and 5 deletions

View file

@ -87,7 +87,12 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
@server.command() @server.command()
@click.option("--host", default="127.0.0.1", help="Host to bind") @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("--port", default=8000, type=int, help="Port to bind")
@click.option("--config", default="config.yaml", help="Path the the configuration file") @click.option(
"--config",
default="config.yaml",
help="Path the the configuration file",
envvar="ARGOS_YAML_FILE",
)
@click.option("--reload", is_flag=True, help="Enable hot reloading") @click.option("--reload", is_flag=True, help="Enable hot reloading")
def start(host, port, config, reload): def start(host, port, config, reload):
"""Starts the server""" """Starts the server"""
@ -124,8 +129,14 @@ def validate_max_results(ctx, param, value):
), ),
callback=validate_max_lock_seconds, callback=validate_max_lock_seconds,
) )
@click.option(
"--config",
default="config.yaml",
help="Path the the configuration file",
envvar="ARGOS_YAML_FILE",
)
@coroutine @coroutine
async def cleandb(max_results, max_lock_seconds): async def cleandb(max_results, max_lock_seconds, config):
"""Clean the database (to run routinely) """Clean the database (to run routinely)
\b \b
@ -135,6 +146,8 @@ async def cleandb(max_results, max_lock_seconds):
# The imports are made here otherwise the agent will need server configuration files. # The imports are made here otherwise the agent will need server configuration files.
from argos.server import queries from argos.server import queries
os.environ["ARGOS_YAML_FILE"] = config
db = await get_db() db = await get_db()
removed = await queries.remove_old_results(db, max_results) removed = await queries.remove_old_results(db, max_results)
updated = await queries.release_old_locks(db, max_lock_seconds) updated = await queries.release_old_locks(db, max_lock_seconds)
@ -144,14 +157,22 @@ async def cleandb(max_results, max_lock_seconds):
@server.command() @server.command()
@click.option(
"--config",
default="config.yaml",
help="Path the the configuration file",
envvar="ARGOS_YAML_FILE",
)
@coroutine @coroutine
async def reload_config(): async def reload_config(config):
"""Read tasks configuration and add/delete tasks in database if needed""" """Read tasks configuration and add/delete tasks in database if needed"""
# The imports are made here otherwise the agent will need server configuration files. # The imports are made here otherwise the agent will need server configuration files.
from argos.server import queries from argos.server import queries
from argos.server.main import get_application, read_config from argos.server.main import get_application, read_config
from argos.server.settings import get_app_settings from argos.server.settings import get_app_settings
os.environ["ARGOS_YAML_FILE"] = config
appli = get_application() appli = get_application()
settings = get_app_settings() settings = get_app_settings()
config = read_config(appli, settings) config = read_config(appli, settings)
@ -164,12 +185,20 @@ async def reload_config():
@server.command() @server.command()
@click.option(
"--config",
default="config.yaml",
help="Path the the configuration file",
envvar="ARGOS_YAML_FILE",
)
@coroutine @coroutine
async def migrate(): async def migrate(config):
"""Run database migrations""" """Run database migrations"""
# The imports are made here otherwise the agent will need server configuration files. # The imports are made here otherwise the agent will need server configuration files.
from argos.server.settings import get_app_settings from argos.server.settings import get_app_settings
os.environ["ARGOS_YAML_FILE"] = config
settings = get_app_settings() settings = get_app_settings()
alembic_cfg = Config("alembic.ini") alembic_cfg = Config("alembic.ini")

View file

@ -122,6 +122,7 @@ Usage: argos server migrate [OPTIONS]
Run database migrations Run database migrations
Options: Options:
--config TEXT Path the the configuration file
--help Show this message and exit. --help Show this message and exit.
``` ```
@ -129,7 +130,7 @@ Options:
--> -->
### Server clean ### Server cleandb
<!-- <!--
.. [[[cog .. [[[cog
help(["server", "cleandb", "--help"]) help(["server", "cleandb", "--help"])
@ -148,6 +149,7 @@ Options:
--max-lock-seconds INTEGER The number of seconds after which a lock is --max-lock-seconds INTEGER The number of seconds after which a lock is
considered stale, must be higher than 60 (the considered stale, must be higher than 60 (the
checks have a timeout value of 60 seconds) checks have a timeout value of 60 seconds)
--config TEXT Path the the configuration file
--help Show this message and exit. --help Show this message and exit.
``` ```
@ -167,6 +169,7 @@ Usage: argos server reload-config [OPTIONS]
Read tasks configuration and add/delete tasks in database if needed Read tasks configuration and add/delete tasks in database if needed
Options: Options:
--config TEXT Path the the configuration file
--help Show this message and exit. --help Show this message and exit.
``` ```