🔀 Merge branch 'fix-41' into 'develop'

🔊 — Add a warning messages in the logs if there is no tasks in database. (fix #41)

See merge request framasoft/framaspace/argos!49
This commit is contained in:
Luc Didry 2024-05-28 07:29:23 +00:00
commit b9e2e62055
3 changed files with 19 additions and 8 deletions

View file

@ -4,6 +4,7 @@
- 💄📯 — Improve notifications and result(s) pages
- 🔊 — Add level of log before the log message
— 🔊 — Add a warning messages in the logs if there is no tasks in database. (fix #41)
## 0.1.1

View file

@ -8,7 +8,7 @@ from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker
from argos.logging import logger
from argos.server import models, routes
from argos.server import models, routes, queries
from argos.server.settings import get_app_settings, read_yaml_config
@ -49,7 +49,16 @@ def create_start_app_handler(appli):
async def _get_db():
setup_database(appli)
return await connect_to_db(appli)
db = await connect_to_db(appli)
tasks_count = await queries.count_tasks(db)
if tasks_count == 0:
logger.warning(
"There is no tasks in the database. "
'Please launch the command "argos server reload-config"'
)
return db
return _get_db

View file

@ -1,7 +1,7 @@
"""Functions to ease SQL queries management"""
from datetime import datetime, timedelta
from hashlib import sha256
from typing import List
from typing import List, Union
from urllib.parse import urljoin
from sqlalchemy import desc, func
@ -48,8 +48,9 @@ async def create_result(db: Session, agent_result: schemas.AgentResult, agent_id
return result
async def count_tasks(db: Session, selected=False):
async def count_tasks(db: Session, selected: Union[None, bool] = None):
query = db.query(Task)
if selected is not None:
if selected:
query = query.filter(Task.selected_by is not None)
else: