Skip to content

Commit

Permalink
v2.15.1 Adding limit_response to get_tasks method (#80)
Browse files Browse the repository at this point in the history
* v2.15.1 Adding limit_response

* v2.15.1 Adding limit_response

* Adding comments and information on Readme

* Adding comments and information on Readme

* Fixing lint line too long

* nit comment changes

---------

Co-authored-by: Fatih Kurtoglu <[email protected]>
  • Loading branch information
FernandoLopez85 and fatihkurtoglu committed Nov 6, 2023
1 parent b5815c3 commit 12d1721
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ Accessing ``task.params`` child objects directly at task level is **deprecated**
task.params["geometries"] # task.geometries is DEPRECATED
task.params["attachment"] # task.attachment is DEPRECATED
If you use the ``limited_response = True`` filter in ``get_tasks()``, you will only receive the following attributes: ``task_id``, ``status``, ``metadata``, ``project`` and ``otherVersion``.

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`` and ``tags``.
``created_after``, ``created_before``, ``tags`` and ``limited_response``.

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

Expand Down
15 changes: 14 additions & 1 deletion scaleapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def tasks(self, **kwargs) -> Tasklist:
If true, returns a pre-signed s3 url for the
attachment used to create the task.
limited_response (bool):
If true, returns task response of the following fields:
task_id, status, metadata, project, otherVersion.
next_token (str):
Can be use to fetch the next page of tasks
"""
Expand All @@ -293,6 +297,7 @@ def tasks(self, **kwargs) -> Tasklist:
"updated_after",
"unique_id",
"include_attachment_url",
"limited_response",
}

for key in kwargs:
Expand Down Expand Up @@ -329,6 +334,7 @@ def get_tasks(
created_before: str = None,
tags: Union[List[str], str] = None,
include_attachment_url: bool = True,
limited_response: bool = 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 @@ -392,6 +398,10 @@ def get_tasks(
If true, returns a pre-signed s3 url for the
attachment used to create the task.
limited_response (bool):
If true, returns task response of the following fields:
task_id, status, metadata, project, otherVersion.
Yields:
Generator[Task]:
Expand All @@ -416,6 +426,7 @@ def get_tasks(
created_before,
tags,
include_attachment_url,
limited_response,
)

while has_more:
Expand All @@ -424,7 +435,6 @@ def get_tasks(
tasks = self.tasks(**tasks_args)
for task in tasks.docs:
yield task

next_token = tasks.next_token
has_more = tasks.has_more

Expand Down Expand Up @@ -545,6 +555,7 @@ def _process_tasks_endpoint_args(
created_before: str = None,
tags: Union[List[str], str] = None,
include_attachment_url: bool = True,
limited_response: bool = None,
):
"""Generates args for /tasks endpoint."""
tasks_args = {
Expand All @@ -563,6 +574,8 @@ def _process_tasks_endpoint_args(

if status:
tasks_args["status"] = status.value
if limited_response:
tasks_args["limited_response"] = limited_response
if task_type:
tasks_args["type"] = task_type.value
if review_status:
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.0"
__version__ = "2.15.1"
__package_name__ = "scaleapi"

0 comments on commit 12d1721

Please sign in to comment.