Skip to content

Adding limit option to get_tasks method #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Retrieve List of Tasks

Retrieve a list of `Task` objects, with filters for: ``project_name``, ``batch_name``, ``type``, ``status``,
``review_status``, ``unique_id``, ``completed_after``, ``completed_before``, ``updated_after``, ``updated_before``,
``created_after``, ``created_before``, ``tags`` and ``limited_response``.
``created_after``, ``created_before``, ``tags``, ``limited_response`` and ``limit``.

``get_tasks()`` is a **generator** method and yields ``Task`` objects.

Expand Down
7 changes: 7 additions & 0 deletions scaleapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def get_tasks(
tags: Union[List[str], str] = None,
include_attachment_url: bool = True,
limited_response: bool = None,
limit: int = None,
) -> Generator[Task, None, None]:
"""Retrieve all tasks as a `generator` method, with the
given parameters. This methods handles pagination of
Expand Down Expand Up @@ -402,6 +403,9 @@ def get_tasks(
If true, returns task response of the following fields:
task_id, status, metadata, project, otherVersion.

limit (int):
Determines the task count per request (1-100)
For large sized tasks, use a smaller limit

Yields:
Generator[Task]:
Expand Down Expand Up @@ -429,6 +433,9 @@ def get_tasks(
limited_response,
)

if limit:
tasks_args["limit"] = limit

while has_more:
tasks_args["next_token"] = next_token

Expand Down
2 changes: 1 addition & 1 deletion scaleapi/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.15.5"
__version__ = "2.15.6"
__package_name__ = "scaleapi"
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def test_get_tasks():
for task in client.get_tasks(
project_name=TEST_PROJECT_NAME,
batch_name=batch.name,
limit=1,
):
assert task.id in task_ids

Expand Down