Skip to content

Commit

Permalink
Adding limit option to get_tasks method (#86)
Browse files Browse the repository at this point in the history
* Adding limit option to get_tasks method

* add test case

* lint
  • Loading branch information
fatihkurtoglu committed May 30, 2024
1 parent d6cb2be commit aea93db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
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

0 comments on commit aea93db

Please sign in to comment.