Skip to content

Commit

Permalink
Merge pull request #845 from ashleyheath/issue-708
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim authored Oct 5, 2023
2 parents 3da3cc6 + 3c5240f commit c126d8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions procrastinate/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 29 additions & 2 deletions tests/unit/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ 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")

Expand All @@ -266,8 +268,21 @@ 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")

Expand All @@ -288,6 +303,18 @@ 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(
Expand Down

0 comments on commit c126d8f

Please sign in to comment.