🔀 Merge branch 'doc/improvement' into 'main'

📝 — Improve documentation (fix #21)

Closes #21

See merge request framasoft/framaspace/argos!36
This commit is contained in:
Alexis Metaireau 2024-03-25 14:03:46 +00:00
commit e264f8a068
13 changed files with 92 additions and 38 deletions

View file

@ -60,13 +60,13 @@ def server():
def agent(server_url, auth, max_tasks, wait_time, log_level): def agent(server_url, auth, max_tasks, wait_time, log_level):
"""Get and run tasks to the provided server. Will wait for new tasks. """Get and run tasks to the provided server. Will wait for new tasks.
Usage: argos agent https://argos.server "auth-token-here" Usage: argos agent https://argos.example.org "auth-token-here"
Alternatively, you can use the following environment variables to avoid passing Alternatively, you can use the following environment variables to avoid passing
arguments to the agent on the command line: arguments to the agent on the command line:
\b \b
ARGOS_AGENT_SERVER_URL=https://argos.server ARGOS_AGENT_SERVER_URL=https://argos.example.org
ARGOS_AGENT_TOKEN=auth-token-here ARGOS_AGENT_TOKEN=auth-token-here
""" """
click.echo("Starting argos agent. Will retry forever.") click.echo("Starting argos agent. Will retry forever.")
@ -83,7 +83,7 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
@click.option("--config", default="config.yaml", help="Path the the configuration file") @click.option("--config", default="config.yaml", help="Path the the configuration 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"""
os.environ["ARGOS_YAML_FILE"] = config os.environ["ARGOS_YAML_FILE"] = config
uvicorn.run("argos.server:app", host=host, port=port, reload=reload) uvicorn.run("argos.server:app", host=host, port=port, reload=reload)
@ -136,7 +136,7 @@ async def cleandb(max_results, max_lock_seconds):
@server.command() @server.command()
@coroutine @coroutine
async def reload_config(): async def reload_config():
"""Read tasks config 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

View file

@ -17,5 +17,5 @@ WantedBy=multi-user.target
# NB: it may be better to # NB: it may be better to
# - use a dedicated user # - use a dedicated user
# - use a EnvironmentFile=/etc/default/argos-agent in order enable configuration # - use a EnvironmentFile=/etc/default/argos-agent in order to enable configuration
# changes without doing a systemctl daemon-reload # changes without doing a systemctl daemon-reload

View file

@ -8,11 +8,16 @@ PartOf=postgresql.service
[Service] [Service]
User=www-data User=www-data
WorkingDirectory=/var/www/argos/ WorkingDirectory=/var/www/argos/
Environment="ARGOS_SERVER_WORKERS=4"
ExecStartPre=/var/www/argos/venv/bin/argos server migrate ExecStartPre=/var/www/argos/venv/bin/argos server migrate
ExecStartPre=/var/www/argos/venv/bin/argos server reload-config ExecStartPre=/var/www/argos/venv/bin/argos server reload-config
ExecStart=/var/www/argos/venv/bin/argos server start ExecStart=/var/www/argos/venv/bin/gunicorn "argos.server.main:get_application()" -w $ARGOS_SERVER_WORKERS -k uvicorn.workers.UvicornWorker
ExecReload=/var/www/argos/venv/bin/argos server reload ExecReload=/var/www/argos/venv/bin/argos server reload
SyslogIdentifier=argos-server SyslogIdentifier=argos-server
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
# NB: it may be better to
# - use a EnvironmentFile=/etc/default/argos-server in order to enable configuration
# changes without doing a systemctl daemon-reload

View file

@ -40,19 +40,21 @@ Commands:
.. ]]] --> .. ]]] -->
```man ```man
Usage: argos agent [OPTIONS] SERVER AUTH Usage: argos agent [OPTIONS] SERVER_URL AUTH
Get and run tasks to the provided server. Will wait for new tasks. Get and run tasks to the provided server. Will wait for new tasks.
Usage: argos agent https://argos.server "auth-token-here" Usage: argos agent https://argos.example.org "auth-token-here"
Alternatively, you can use the following environment variables to avoid Alternatively, you can use the following environment variables to avoid
passing arguments to the agent on the command line: passing arguments to the agent on the command line:
ARGOS_AGENT_SERVER_URL=https://argos.server ARGOS_AGENT_TOKEN=auth-token-
here ARGOS_AGENT_SERVER_URL=https://argos.example.org
ARGOS_AGENT_TOKEN=auth-token-here
Options: Options:
--max-tasks INTEGER Number of concurrent tasks this agent can run --max-tasks INTEGER Number of concurrent tasks this agent can
run
--wait-time INTEGER Waiting time between two polls on the server --wait-time INTEGER Waiting time between two polls on the server
(seconds) (seconds)
--log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL] --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
@ -76,7 +78,9 @@ Options:
Commands: Commands:
cleandb Clean the database (to run routinely) cleandb Clean the database (to run routinely)
start Starts the server. migrate Run database migrations
reload-config Read tasks config and add/delete tasks in database if...
start Starts the server
``` ```
<!--[[[end]]] <!--[[[end]]]
@ -91,7 +95,7 @@ Commands:
```man ```man
Usage: argos server start [OPTIONS] Usage: argos server start [OPTIONS]
Starts the server. Starts the server
Options: Options:
--host TEXT Host to bind --host TEXT Host to bind
@ -104,6 +108,26 @@ Options:
<!--[[[end]]] <!--[[[end]]]
--> -->
### Server migrate
<!--
.. [[[ cog
help(["server", "migrate", "--help"])
.. ]]] -->
```man
Usage: argos server migrate [OPTIONS]
Run database migrations
Options:
--help Show this message and exit.
```
<!--[[[end]]]
-->
### Server clean ### Server clean
<!-- <!--
.. [[[cog .. [[[cog
@ -115,15 +139,36 @@ Usage: argos server cleandb [OPTIONS]
Clean the database (to run routinely) Clean the database (to run routinely)
- Removes old results from the database. - Removes locks from tasks that have - Removes old results from the database.
been locked for too long. - Removes locks from tasks that have been locked for too long.
Options: Options:
--max-results INTEGER Number of results per tasks to keep --max-results INTEGER Number of results per task to keep
--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 considered stale, must be higher than 60 (the
checks have a timeout value of 60 seconds)
--help Show this message and exit. --help Show this message and exit.
``` ```
<!--[[[end]]] <!--[[[end]]]
--> -->
### Server reload-config
<!--
.. [[[ cog
help(["server", "reload-config", "--help"])
.. ]]] -->
```man
Usage: argos server reload-config [OPTIONS]
Read tasks configuration and add/delete tasks in database if needed
Options:
--help Show this message and exit.
```
<!--[[[end]]]
-->

View file

@ -17,9 +17,3 @@ caption: /etc/systemd/system/argos-agent.service
caption: /etc/systemd/system/argos-server.service caption: /etc/systemd/system/argos-server.service
--- ---
``` ```
Please note that it might be better to use Gunicorn with a Uvicorn worker, [as specified in the Uvicorn docs](https://www.uvicorn.org/#running-with-gunicorn):
```bash
gunicorn example:app -w 4 -k uvicorn.workers.UvicornWorker -b '127.0.0.1:8000'
```

View file

@ -9,3 +9,5 @@ you're done, you can create a new migration.
```bash ```bash
venv/bin/alembic revision --autogenerate -m "migration reason" venv/bin/alembic revision --autogenerate -m "migration reason"
``` ```
Edit the created file to remove comments and adapt it to make sure the migration is complete (Alembic is not powerful enough to cover all the corner cases).

View file

@ -13,11 +13,12 @@ class Task {
- selected_at - selected_at
- completed_at - completed_at
- next_run - next_run
- severity
- last_severity_update
} }
class Result{ class Result{
- task : Task - task : Task
- task_id - task_id
- task
- agent_id - agent_id
- submitted_at - submitted_at
- status - status
@ -27,6 +28,8 @@ class Result{
Result "*" o-- "1" Task : has many Result "*" o-- "1" Task : has many
``` ```
The `severity` attribute in `Task` is the severity of the last `Result` submitted by an agent.
```{literalinclude} ../../argos/server/models.py ```{literalinclude} ../../argos/server/models.py
--- ---

View file

@ -27,3 +27,4 @@ The server acts like a job queue. When an agent asks for work, the server will:
When it receives the results, it will: When it receives the results, it will:
- Remove the "selected by" and "selected at" fields - Remove the "selected by" and "selected at" fields
- Compute the next execution date. - Compute the next execution date.
- Send alerts if needed

View file

@ -10,7 +10,8 @@
- [SQLAlchemy](https://www.sqlalchemy.org/) is the ORM we use, to connect to our database and issue queries; - [SQLAlchemy](https://www.sqlalchemy.org/) is the ORM we use, to connect to our database and issue queries;
- [Alembic](https://alembic.sqlalchemy.org) is used for DB migrations; - [Alembic](https://alembic.sqlalchemy.org) is used for DB migrations;
- [Tenacity](https://github.com/jd/tenacity) a small utility to retry a function in case an error occured; - [Tenacity](https://github.com/jd/tenacity) a small utility to retry a function in case an error occured;
- [Uvicorn](https://www.uvicorn.org/) is the tool used to run our server. - [Uvicorn](https://www.uvicorn.org/) is the tool used to run our server;
- [Gunicorn](https://gunicorn.org/) is the recommended WSGI HTTP server for production.
## CSS framework ## CSS framework

View file

@ -51,6 +51,12 @@ cli
api api
``` ```
```{toctree}
:caption: Deployment
:hidden:
deployment/systemd
```
```{toctree} ```{toctree}
:caption: Configuration :caption: Configuration
:hidden: :hidden:
@ -69,9 +75,3 @@ developer/projects
changelog changelog
``` ```
```{toctree}
:caption: Deployment
:hidden:
deployment/systemd
```

View file

@ -3,7 +3,7 @@
## Requirements ## Requirements
- Python 3.11+ - Python 3.11+
- PostgreSQL 13+ - PostgreSQL 13+ (for production)
## Getting dependencies ## Getting dependencies
@ -35,6 +35,8 @@ caption: .env
--- ---
``` ```
Please note that the only supported database engines are SQLite for development and PostgreSQL for production.
Then you can start the server: Then you can start the server:
```bash ```bash

View file

@ -1,12 +1,12 @@
# Installing PostgreSQL # Use with PostgreSQL
If you intend to use argos with Postgresql, you can install it with the following commands: If you intend to use argos with Postgresql, which is recommended for production, you can install it with the following commands:
```bash ```bash
pip install -e ".[postgres]" pip install -e ".[postgres]"
``` ```
Here are a few steps for you to install postgresql on your system: Here are a few steps for you to install PostgreSQL on your system:
## Debian ## Debian

View file

@ -30,6 +30,7 @@ dependencies = [
"sqlalchemy-utils>=0.41,<1", "sqlalchemy-utils>=0.41,<1",
"tenacity>=8.2,<9", "tenacity>=8.2,<9",
"uvicorn>=0.23,<1", "uvicorn>=0.23,<1",
"gunicorn>=21.2,<22",
] ]
[project.optional-dependencies] [project.optional-dependencies]