Skip to content

Commit aea93db

Browse files
Adding limit option to get_tasks method (#86)
* Adding limit option to get_tasks method * add test case * lint
1 parent d6cb2be commit aea93db

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Retrieve List of Tasks
178178

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

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

scaleapi/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def get_tasks(
335335
tags: Union[List[str], str] = None,
336336
include_attachment_url: bool = True,
337337
limited_response: bool = None,
338+
limit: int = None,
338339
) -> Generator[Task, None, None]:
339340
"""Retrieve all tasks as a `generator` method, with the
340341
given parameters. This methods handles pagination of
@@ -402,6 +403,9 @@ def get_tasks(
402403
If true, returns task response of the following fields:
403404
task_id, status, metadata, project, otherVersion.
404405
406+
limit (int):
407+
Determines the task count per request (1-100)
408+
For large sized tasks, use a smaller limit
405409
406410
Yields:
407411
Generator[Task]:
@@ -429,6 +433,9 @@ def get_tasks(
429433
limited_response,
430434
)
431435

436+
if limit:
437+
tasks_args["limit"] = limit
438+
432439
while has_more:
433440
tasks_args["next_token"] = next_token
434441

scaleapi/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.15.5"
1+
__version__ = "2.15.6"
22
__package_name__ = "scaleapi"

tests/test_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def test_get_tasks():
406406
for task in client.get_tasks(
407407
project_name=TEST_PROJECT_NAME,
408408
batch_name=batch.name,
409+
limit=1,
409410
):
410411
assert task.id in task_ids
411412

0 commit comments

Comments
 (0)