From 12d1721588c2afa3b985c646d216598786baec06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20L=C3=B3pez?= <132707066+FernandoLopez85@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:03:25 -0600 Subject: [PATCH] v2.15.1 Adding limit_response to get_tasks method (#80) * 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 --- README.rst | 4 +++- scaleapi/__init__.py | 15 ++++++++++++++- scaleapi/_version.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index e3d554e..6003390 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index b687268..ae96c64 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -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 """ @@ -293,6 +297,7 @@ def tasks(self, **kwargs) -> Tasklist: "updated_after", "unique_id", "include_attachment_url", + "limited_response", } for key in kwargs: @@ -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 @@ -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]: @@ -416,6 +426,7 @@ def get_tasks( created_before, tags, include_attachment_url, + limited_response, ) while has_more: @@ -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 @@ -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 = { @@ -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: diff --git a/scaleapi/_version.py b/scaleapi/_version.py index 74c7b31..704e352 100644 --- a/scaleapi/_version.py +++ b/scaleapi/_version.py @@ -1,2 +1,2 @@ -__version__ = "2.15.0" +__version__ = "2.15.1" __package_name__ = "scaleapi"