From 2f0cf175b02e245233bb5d92ac362eb026741eb2 Mon Sep 17 00:00:00 2001 From: Eva Bardou <bardou@teklia.com> Date: Fri, 8 Mar 2024 14:32:27 +0000 Subject: [PATCH] Log a message when everything went well as well --- arkindex_worker/worker/__init__.py | 14 ++++++++------ tests/test_dataset_worker.py | 16 ++++++++++------ tests/test_elements_worker/test_worker.py | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/arkindex_worker/worker/__init__.py b/arkindex_worker/worker/__init__.py index 98dccc80..aab6c9ea 100644 --- a/arkindex_worker/worker/__init__.py +++ b/arkindex_worker/worker/__init__.py @@ -230,12 +230,13 @@ class ElementsWorker( with contextlib.suppress(Exception): self.update_activity(element.id, ActivityState.Error) + message = f'Ran on {count} element{"s"[:count>1]}: {count - failed} completed, {failed} failed' if failed: - logger.error( - f"Ran on {count} elements: {count - failed} completed, {failed} failed" - ) + logger.error(message) if failed >= count: # Everything failed! sys.exit(1) + else: + logger.info(message) def process_element(self, element: Element | CachedElement): """ @@ -505,9 +506,10 @@ class DatasetWorker(BaseWorker, DatasetMixin, TaskMixin): if dataset_artifact: dataset_artifact.unlink(missing_ok=True) + message = f'Ran on {count} dataset{"s"[:count>1]}: {count - failed} completed, {failed} failed' if failed: - logger.error( - f"Ran on {count} datasets: {count - failed} completed, {failed} failed" - ) + logger.error(message) if failed >= count: # Everything failed! sys.exit(1) + else: + logger.info(message) diff --git a/tests/test_dataset_worker.py b/tests/test_dataset_worker.py index f4a44ae9..18cd43e1 100644 --- a/tests/test_dataset_worker.py +++ b/tests/test_dataset_worker.py @@ -512,7 +512,7 @@ def test_run_initial_dataset_state_error( if generator else [] ) + [ - (logging.ERROR, "Ran on 1 datasets: 0 completed, 1 failed"), + (logging.ERROR, "Ran on 1 dataset: 0 completed, 1 failed"), ] @@ -577,7 +577,7 @@ def test_run_update_dataset_state_api_error( ], ( logging.ERROR, - "Ran on 1 datasets: 0 completed, 1 failed", + "Ran on 1 dataset: 0 completed, 1 failed", ), ] @@ -639,7 +639,7 @@ def test_run_download_dataset_artifact_api_error( ), ( logging.ERROR, - "Ran on 1 datasets: 0 completed, 1 failed", + "Ran on 1 dataset: 0 completed, 1 failed", ), ] @@ -690,7 +690,7 @@ def test_run_no_downloaded_artifact_error( ), ( logging.ERROR, - "Ran on 1 datasets: 0 completed, 1 failed", + "Ran on 1 dataset: 0 completed, 1 failed", ), ] @@ -792,7 +792,9 @@ def test_run( assert [(level, message) for _, level, message in caplog.record_tuples] == [ (logging.INFO, "Loaded Worker Fake worker @ 123412 from API"), (logging.INFO, "Processing Dataset (dataset_id) (1/1)"), - ] + extra_logs + *extra_logs, + (logging.INFO, "Ran on 1 dataset: 1 completed, 0 failed"), + ] @pytest.mark.parametrize( @@ -890,4 +892,6 @@ def test_run_read_only( assert [(level, message) for _, level, message in caplog.record_tuples] == [ (logging.WARNING, "Running without any extra configuration"), (logging.INFO, "Processing Dataset (dataset_id) (1/1)"), - ] + extra_logs + *extra_logs, + (logging.INFO, "Ran on 1 dataset: 1 completed, 0 failed"), + ] diff --git a/tests/test_elements_worker/test_worker.py b/tests/test_elements_worker/test_worker.py index d7482bad..c237b4c7 100644 --- a/tests/test_elements_worker/test_worker.py +++ b/tests/test_elements_worker/test_worker.py @@ -310,7 +310,7 @@ def test_start_activity_error( ), ] assert logger.error.call_args_list == [ - mocker.call("Ran on 1 elements: 0 completed, 1 failed") + mocker.call("Ran on 1 element: 0 completed, 1 failed") ] -- GitLab