From 6ac76bda2965044b04341e1e05c7db953384cd4b Mon Sep 17 00:00:00 2001 From: Dennis Priskorn <68460690+dpriskorn@users.noreply.github.com> Date: Sun, 16 Jan 2022 20:45:12 +0100 Subject: [PATCH] jobs.py: get_validated_main_subjects_as_jobs(): Add logging. console.py: print_job_statistics(): Fix wrong logic. --- src/helpers/console.py | 2 +- src/helpers/jobs.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/helpers/console.py b/src/helpers/console.py index 49e8b60..6a19f23 100644 --- a/src/helpers/console.py +++ b/src/helpers/console.py @@ -120,7 +120,7 @@ def print_finished(): def print_job_statistics(jobs: List[BatchJob] = None): if jobs is None: raise ValueError("jobs was None") - if len(jobs) > 0: + if len(jobs) == 0: console.print("The jobs list is empty") else: console.print(f"The jobs list now contain a total of {len(jobs)} " diff --git a/src/helpers/jobs.py b/src/helpers/jobs.py index 0321c2f..4c808de 100644 --- a/src/helpers/jobs.py +++ b/src/helpers/jobs.py @@ -1,6 +1,7 @@ from __future__ import annotations import argparse +import logging import random from datetime import datetime from typing import Union, List, TYPE_CHECKING @@ -142,7 +143,7 @@ def get_validated_main_subjects_as_jobs(args: argparse.Namespace = None, main_subjects: List[str] = None, jobs: List[BatchJob] = None): """This function randomly picks a subject and present it for validation""" - # logger = logging.getLogger(__name__) + logger = logging.getLogger(__name__) if jobs is None: raise ValueError("jobs was None") if not isinstance(jobs, List): @@ -151,8 +152,10 @@ def get_validated_main_subjects_as_jobs(args: argparse.Namespace = None, raise ValueError("args was None") if main_subjects is None: raise ValueError("main subjects was None") + jobs = jobs subjects_not_picked_yet = main_subjects while True: + # Check if we have any subjects left in the list if len(subjects_not_picked_yet) > 0: console.print(f"Picking a random main subject") qid = random.choice(subjects_not_picked_yet) @@ -164,6 +167,7 @@ def get_validated_main_subjects_as_jobs(args: argparse.Namespace = None, confirmation=args.no_confirmation) if job is not None: jobs.append(job) + logger.debug(f"joblist now has {len(jobs)} jobs") print_job_statistics(jobs=jobs) if len(subjects_not_picked_yet) > 0: if (