Skip to content

Commit

Permalink
Merge pull request #1168 from openradx/rename-error-to-failed
Browse files Browse the repository at this point in the history
Rename remove_error and include_error to remove_failed and include_failed
  • Loading branch information
medihack authored Aug 19, 2024
2 parents a5f1e04 + 57c990c commit 24cd54b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/howto/production/delete_finished_jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def remove_old_jobs(context, timestamp):
return await builtin_tasks.remove_old_jobs(
context,
max_hours=72,
remove_error=True,
remove_failed=True,
remove_cancelled=True,
remove_aborted=True,
)
Expand Down
6 changes: 3 additions & 3 deletions procrastinate/builtin_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def remove_old_jobs(
*,
max_hours: int,
queue: str | None = None,
remove_error: bool | None = False,
remove_failed: bool | None = False,
remove_cancelled: bool | None = False,
remove_aborted: bool | None = False,
) -> None:
Expand All @@ -26,7 +26,7 @@ async def remove_old_jobs(
queue :
The name of the queue in which jobs will be deleted. If not specified, the
task will delete jobs from all queues.
remove_error:
remove_failed:
By default only successful jobs will be removed. When this parameter is True
failed jobs will also be deleted.
remove_cancelled:
Expand All @@ -39,7 +39,7 @@ async def remove_old_jobs(
await context.app.job_manager.delete_old_jobs(
nb_hours=max_hours,
queue=queue,
include_error=remove_error,
include_failed=remove_failed,
include_cancelled=remove_cancelled,
include_aborted=remove_aborted,
)
6 changes: 3 additions & 3 deletions procrastinate/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def delete_old_jobs(
self,
nb_hours: int,
queue: str | None = None,
include_error: bool | None = False,
include_failed: bool | None = False,
include_cancelled: bool | None = False,
include_aborted: bool | None = False,
) -> None:
Expand All @@ -192,7 +192,7 @@ async def delete_old_jobs(
Consider jobs that been in a final state for more than ``nb_hours``
queue:
Filter by job queue name
include_error:
include_failed:
If ``True``, also consider errored jobs. ``False`` by default
include_cancelled:
If ``True``, also consider cancelled jobs. ``False`` by default.
Expand All @@ -201,7 +201,7 @@ async def delete_old_jobs(
"""
# We only consider finished jobs by default
statuses = [jobs.Status.SUCCEEDED.value]
if include_error:
if include_failed:
statuses.append(jobs.Status.FAILED.value)
if include_cancelled:
statuses.append(jobs.Status.CANCELLED.value)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async def test_delete_old_jobs_job_doing(


@pytest.mark.parametrize(
"status, nb_hours, queue, include_error, expected_job_count",
"status, nb_hours, queue, include_failed, expected_job_count",
[
# nb_hours
(jobs.Status.SUCCEEDED, 1, None, False, 0),
Expand All @@ -208,7 +208,7 @@ async def test_delete_old_jobs_job_doing(
(jobs.Status.SUCCEEDED, 3, "queue_a", False, 1),
(jobs.Status.SUCCEEDED, 1, "queue_b", False, 1),
(jobs.Status.SUCCEEDED, 1, "queue_b", False, 1),
# include_error
# include_failed
(jobs.Status.FAILED, 1, None, False, 1),
(jobs.Status.FAILED, 1, None, True, 0),
],
Expand All @@ -220,7 +220,7 @@ async def test_delete_old_jobs_parameters(
status,
nb_hours,
queue,
include_error,
include_failed,
expected_job_count,
fetched_job_factory,
):
Expand All @@ -236,7 +236,7 @@ async def test_delete_old_jobs_parameters(
)

await pg_job_manager.delete_old_jobs(
nb_hours=nb_hours, queue=queue, include_error=include_error
nb_hours=nb_hours, queue=queue, include_failed=include_failed
)
jobs_count = len(await get_all("procrastinate_jobs", "id"))
assert jobs_count == expected_job_count
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_builtin_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def test_remove_old_jobs(app: App, job_factory):
job_context.JobContext(app=app, job=job),
max_hours=2,
queue="queue_a",
remove_error=True,
remove_failed=True,
remove_cancelled=True,
remove_aborted=True,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ async def test_get_stalled_jobs_stalled(job_manager, job_factory, connector):


@pytest.mark.parametrize(
"include_error, statuses",
"include_failed, statuses",
[(False, ["succeeded"]), (True, ["succeeded", "failed"])],
)
async def test_delete_old_jobs(
job_manager, job_factory, connector, include_error, statuses, mocker
job_manager, job_factory, connector, include_failed, statuses, mocker
):
await job_manager.delete_old_jobs(
nb_hours=5, queue="marsupilami", include_error=include_error
nb_hours=5, queue="marsupilami", include_failed=include_failed
)
assert connector.queries == [
(
Expand Down

0 comments on commit 24cd54b

Please sign in to comment.