diff --git a/meilisearch_python_async/task.py b/meilisearch_python_async/task.py index b80a4651..1f6fbb94 100644 --- a/meilisearch_python_async/task.py +++ b/meilisearch_python_async/task.py @@ -25,6 +25,8 @@ async def cancel_tasks( ) -> TaskInfo: """Cancel a list of enqueued or processing tasks. + Defaults to cancelling all tasks. + Args: uids: A list of task UIDs to cancel. @@ -72,6 +74,11 @@ async def cancel_tasks( parameters["beforeStartedAt"] = str(before_started_at) if after_finished_at: parameters["afterFinishedAt"] = str(after_finished_at) + + if not parameters: + # Cancel all tasks if no parmaeters provided + parameters["statuses"] = "enqueued,processing" + url = f"tasks/cancel?{urlencode(parameters)}" response = await http_client.post(url) diff --git a/tests/test_task.py b/tests/test_task.py index 192283f2..7fada71d 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -4,6 +4,18 @@ from meilisearch_python_async.task import cancel_tasks, get_task, get_tasks, wait_for_task +async def test_cancel_every_task(test_client): + task = await cancel_tasks(test_client.http_client, statuses=["enqueued", "processing"]) + tasks = await get_tasks(test_client.http_client, types="taskCancelation") + + assert task.task_uid is not None + assert task.index_uids is None + assert task.status in {"enqueued", "processing", "succeeded"} + assert task.task_type == "taskCancelation" + assert tasks[0].details is not None + assert "statuses=enqueued%2Cprocessing" in tasks[0].details["originalFilter"] + + async def test_cancel_tasks(test_client): task = await cancel_tasks(test_client.http_client, uids=["1", "2"]) tasks = await get_tasks(test_client.http_client, types=["taskCancelation"]) @@ -16,12 +28,16 @@ async def test_cancel_tasks(test_client): assert "uids=1%2C2" in tasks[0].details["originalFilter"] -async def test_cancel_every_task(test_client): - task = await cancel_tasks(test_client.http_client, statuses=["enqueued", "processing"]) +async def test_cancel_task_no_params(test_client): + task = await cancel_tasks(test_client.http_client) tasks = await get_tasks(test_client.http_client, types="taskCancelation") assert task.task_uid is not None assert task.index_uids is None + assert task.status in {"enqueued", "processing", "succeeded"} + assert task.task_type == "taskCancelation" + assert tasks[0].details is not None + assert "statuses=enqueued%2Cprocessing" in tasks[0].details["originalFilter"] async def test_get_tasks(empty_index, small_movies):