From 7bfe676b5c3f6d78395fea6ed45ea13f8e454e5d Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 23 May 2024 16:12:12 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=8A=20=E2=80=94=20Add=20a=20warnin?= =?UTF-8?q?g=20messages=20in=20the=20logs=20if=20there=20is=20no=20tasks?= =?UTF-8?q?=20in=20database.=20(fix=20#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + argos/server/main.py | 13 +++++++++++-- argos/server/queries.py | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7954f1d..d452ff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/argos/server/main.py b/argos/server/main.py index 856a116..e91b226 100644 --- a/argos/server/main.py +++ b/argos/server/main.py @@ -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, all_tasks=True) + 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 diff --git a/argos/server/queries.py b/argos/server/queries.py index cfb3f68..fc6266c 100644 --- a/argos/server/queries.py +++ b/argos/server/queries.py @@ -48,11 +48,11 @@ 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=False, all_tasks=False): query = db.query(Task) if selected: query = query.filter(Task.selected_by is not None) - else: + elif not all_tasks: query = query.filter(Task.selected_by is None) return query.count() From be492ed2eec974f85764149b6323a1d291ab54f3 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Mon, 27 May 2024 10:54:08 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20=E2=80=94=20Modify=20count?= =?UTF-8?q?=5Ftasks=20behavior,=20improve=20its=20signature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- argos/server/main.py | 2 +- argos/server/queries.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/argos/server/main.py b/argos/server/main.py index e91b226..f3d5d14 100644 --- a/argos/server/main.py +++ b/argos/server/main.py @@ -51,7 +51,7 @@ def create_start_app_handler(appli): db = await connect_to_db(appli) - tasks_count = await queries.count_tasks(db, all_tasks=True) + tasks_count = await queries.count_tasks(db) if tasks_count == 0: logger.warning( "There is no tasks in the database. " diff --git a/argos/server/queries.py b/argos/server/queries.py index fc6266c..f9c07f5 100644 --- a/argos/server/queries.py +++ b/argos/server/queries.py @@ -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,12 +48,13 @@ async def create_result(db: Session, agent_result: schemas.AgentResult, agent_id return result -async def count_tasks(db: Session, selected=False, all_tasks=False): +async def count_tasks(db: Session, selected: Union[None, bool] = None): query = db.query(Task) - if selected: - query = query.filter(Task.selected_by is not None) - elif not all_tasks: - query = query.filter(Task.selected_by is None) + if selected is not None: + if selected: + query = query.filter(Task.selected_by is not None) + else: + query = query.filter(Task.selected_by is None) return query.count()