mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 09:52:38 +02:00
🔀 Merge branch 'luc/server-config-options' into 'main'
✨ — Config file option on almost all server commands
See merge request framasoft/framaspace/argos!44
This commit is contained in:
commit
358f6dcd70
2 changed files with 47 additions and 11 deletions
|
@ -87,7 +87,13 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
|
|||
@server.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("--config", default="config.yaml", help="Path the the configuration file")
|
||||
@click.option(
|
||||
"--config",
|
||||
default="config.yaml",
|
||||
help="Path of the configuration file. "
|
||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||
envvar="ARGOS_YAML_FILE",
|
||||
)
|
||||
@click.option("--reload", is_flag=True, help="Enable hot reloading")
|
||||
def start(host, port, config, reload):
|
||||
"""Starts the server (use only for testing or development!)
|
||||
|
@ -128,8 +134,15 @@ def validate_max_results(ctx, param, value):
|
|||
),
|
||||
callback=validate_max_lock_seconds,
|
||||
)
|
||||
@click.option(
|
||||
"--config",
|
||||
default="config.yaml",
|
||||
help="Path of the configuration file. "
|
||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||
envvar="ARGOS_YAML_FILE",
|
||||
)
|
||||
@coroutine
|
||||
async def cleandb(max_results, max_lock_seconds):
|
||||
async def cleandb(max_results, max_lock_seconds, config):
|
||||
"""Clean the database (to run routinely)
|
||||
|
||||
\b
|
||||
|
@ -139,6 +152,8 @@ async def cleandb(max_results, max_lock_seconds):
|
|||
# The imports are made here otherwise the agent will need server configuration files.
|
||||
from argos.server import queries
|
||||
|
||||
os.environ["ARGOS_YAML_FILE"] = config
|
||||
|
||||
db = await get_db()
|
||||
removed = await queries.remove_old_results(db, max_results)
|
||||
updated = await queries.release_old_locks(db, max_lock_seconds)
|
||||
|
@ -147,15 +162,24 @@ async def cleandb(max_results, max_lock_seconds):
|
|||
click.echo(f"{updated} locks released")
|
||||
|
||||
|
||||
@server.command()
|
||||
@server.command(short_help="Load or reload tasks’ configuration")
|
||||
@click.option(
|
||||
"--config",
|
||||
default="config.yaml",
|
||||
help="Path of the configuration file. "
|
||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||
envvar="ARGOS_YAML_FILE",
|
||||
)
|
||||
@coroutine
|
||||
async def reload_config():
|
||||
"""Read tasks configuration and add/delete tasks in database if needed"""
|
||||
async def reload_config(config):
|
||||
"""Read tasks’ configuration and add/delete tasks in database if needed"""
|
||||
# The imports are made here otherwise the agent will need server configuration files.
|
||||
from argos.server import queries
|
||||
from argos.server.main import get_application, read_config
|
||||
from argos.server.settings import get_app_settings
|
||||
|
||||
os.environ["ARGOS_YAML_FILE"] = config
|
||||
|
||||
appli = get_application()
|
||||
settings = get_app_settings()
|
||||
config = read_config(appli, settings)
|
||||
|
@ -168,12 +192,21 @@ async def reload_config():
|
|||
|
||||
|
||||
@server.command()
|
||||
@click.option(
|
||||
"--config",
|
||||
default="config.yaml",
|
||||
help="Path of the configuration file. "
|
||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||
envvar="ARGOS_YAML_FILE",
|
||||
)
|
||||
@coroutine
|
||||
async def migrate():
|
||||
async def migrate(config):
|
||||
"""Run database migrations"""
|
||||
# The imports are made here otherwise the agent will need server configuration files.
|
||||
from argos.server.settings import get_app_settings
|
||||
|
||||
os.environ["ARGOS_YAML_FILE"] = config
|
||||
|
||||
settings = get_app_settings()
|
||||
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
|
@ -181,7 +214,7 @@ async def migrate():
|
|||
command.upgrade(alembic_cfg, "head")
|
||||
|
||||
|
||||
@server.command()
|
||||
@server.command(short_help="Generate a token for agents")
|
||||
@coroutine
|
||||
async def generate_token():
|
||||
"""Generate a token, which can be used as an agent’s authentication token.
|
||||
|
|
11
docs/cli.md
11
docs/cli.md
|
@ -105,7 +105,7 @@ Usage: argos server start [OPTIONS]
|
|||
Options:
|
||||
--host TEXT Host to bind
|
||||
--port INTEGER Port to bind
|
||||
--config TEXT Path the the configuration file
|
||||
--config TEXT Path of the configuration file
|
||||
--reload Enable hot reloading
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
@ -126,14 +126,15 @@ Usage: argos server migrate [OPTIONS]
|
|||
Run database migrations
|
||||
|
||||
Options:
|
||||
--help Show this message and exit.
|
||||
--config TEXT Path of the configuration file
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
<!--[[[end]]]
|
||||
-->
|
||||
|
||||
|
||||
### Server clean
|
||||
### Server cleandb
|
||||
<!--
|
||||
.. [[[cog
|
||||
help(["server", "cleandb", "--help"])
|
||||
|
@ -152,6 +153,7 @@ Options:
|
|||
--max-lock-seconds INTEGER The number of seconds after which a lock is
|
||||
considered stale, must be higher than 60 (the
|
||||
checks have a timeout value of 60 seconds)
|
||||
--config TEXT Path of the configuration file
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
|
@ -171,7 +173,8 @@ Usage: argos server reload-config [OPTIONS]
|
|||
Read tasks configuration and add/delete tasks in database if needed
|
||||
|
||||
Options:
|
||||
--help Show this message and exit.
|
||||
--config TEXT Path of the configuration file
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
<!--[[[end]]]
|
||||
|
|
Loading…
Reference in a new issue