From 8be7ec743696e75441536f5531fbaa59331df560 Mon Sep 17 00:00:00 2001 From: Ashley Heath Date: Thu, 5 Oct 2023 10:24:48 +0100 Subject: [PATCH 1/2] Log exceptions that trigger job retries at INFO (procrastinate-org/procrastinate#708) --- procrastinate/worker.py | 1 + tests/unit/test_worker.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/procrastinate/worker.py b/procrastinate/worker.py index 940d1254d..75c7f3c04 100644 --- a/procrastinate/worker.py +++ b/procrastinate/worker.py @@ -247,6 +247,7 @@ async def run_job(self, job: jobs.Job, worker_id: int) -> None: if retry_exception: log_title = "Error, to retry" log_action = "job_error_retry" + log_level = logging.INFO raise retry_exception from e raise exceptions.JobError() from e diff --git a/tests/unit/test_worker.py b/tests/unit/test_worker.py index a55521eff..980242e4f 100644 --- a/tests/unit/test_worker.py +++ b/tests/unit/test_worker.py @@ -245,7 +245,10 @@ def task(): assert all([name == record_worker_name for name in worker_names]) -async def test_run_job_error(app): +async def test_run_job_error(app, caplog): + + caplog.set_level("INFO") + def job(a, b): # pylint: disable=unused-argument raise ValueError("nope") @@ -266,8 +269,13 @@ def job(a, b): # pylint: disable=unused-argument with pytest.raises(exceptions.JobError): await test_worker.run_job(job=job, worker_id=3) + assert len([r for r in caplog.records if r.levelname == "ERROR" and "to retry" not in r.message]) == 1 + + +async def test_run_job_retry(app, caplog): + + caplog.set_level("INFO") -async def test_run_job_retry(app): def job(a, b): # pylint: disable=unused-argument raise ValueError("nope") @@ -288,6 +296,9 @@ def job(a, b): # pylint: disable=unused-argument with pytest.raises(exceptions.JobRetry): await test_worker.run_job(job=job, worker_id=3) + assert len([r for r in caplog.records if r.levelname == "INFO" and "to retry" in r.message]) == 1 + assert len([r for r in caplog.records if r.levelname == "ERROR"]) == 0 + async def test_run_job_not_found(app): job = jobs.Job( From 3c5240f898d72069d483696d16f8d960aa8aaa6f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 09:29:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/test_worker.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_worker.py b/tests/unit/test_worker.py index 980242e4f..cdb6cf847 100644 --- a/tests/unit/test_worker.py +++ b/tests/unit/test_worker.py @@ -246,7 +246,6 @@ def task(): async def test_run_job_error(app, caplog): - caplog.set_level("INFO") def job(a, b): # pylint: disable=unused-argument @@ -269,11 +268,19 @@ def job(a, b): # pylint: disable=unused-argument with pytest.raises(exceptions.JobError): await test_worker.run_job(job=job, worker_id=3) - assert len([r for r in caplog.records if r.levelname == "ERROR" and "to retry" not in r.message]) == 1 + assert ( + len( + [ + r + for r in caplog.records + if r.levelname == "ERROR" and "to retry" not in r.message + ] + ) + == 1 + ) async def test_run_job_retry(app, caplog): - caplog.set_level("INFO") def job(a, b): # pylint: disable=unused-argument @@ -296,7 +303,16 @@ def job(a, b): # pylint: disable=unused-argument with pytest.raises(exceptions.JobRetry): await test_worker.run_job(job=job, worker_id=3) - assert len([r for r in caplog.records if r.levelname == "INFO" and "to retry" in r.message]) == 1 + assert ( + len( + [ + r + for r in caplog.records + if r.levelname == "INFO" and "to retry" in r.message + ] + ) + == 1 + ) assert len([r for r in caplog.records if r.levelname == "ERROR"]) == 0