From 262cc5bf121e0a81c4d567e47b09fe3477b4841a Mon Sep 17 00:00:00 2001 From: ykeremy Date: Mon, 7 Oct 2024 21:07:57 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'skyvern/'=20wi?= =?UTF-8?q?th=20remote=20'skyvern/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > [!IMPORTANT] > Add `only_standalone_tasks` query parameter to filter tasks not part of a workflow run in `get_tasks()` and `get_agent_tasks()`. > > - **Behavior**: > - Add `only_standalone_tasks` parameter to `get_tasks()` in `client.py` to filter tasks not part of a workflow run. > - In `agent_protocol.py`, add `only_standalone_tasks` query parameter to `get_agent_tasks()`. > - Raise `HTTPException` if `only_standalone_tasks` and `workflow_run_id` are used together in `get_agent_tasks()`. > - **Misc**: > - Update docstring in `get_tasks()` in `client.py` to include `only_standalone_tasks` parameter. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=Skyvern-AI%2Fskyvern-cloud&utm_source=github&utm_medium=referral) for ea78ed3f6e3c0609d73848b6020606ac1d742e2a. It will automatically update as commits are pushed. --- skyvern/forge/sdk/db/client.py | 4 ++++ skyvern/forge/sdk/routes/agent_protocol.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/skyvern/forge/sdk/db/client.py b/skyvern/forge/sdk/db/client.py index 2053fc0ab..1e9fb5b2d 100644 --- a/skyvern/forge/sdk/db/client.py +++ b/skyvern/forge/sdk/db/client.py @@ -438,6 +438,7 @@ async def get_tasks( task_status: list[TaskStatus] | None = None, workflow_run_id: str | None = None, organization_id: str | None = None, + only_standalone_tasks: bool = False, ) -> list[Task]: """ Get all tasks. @@ -445,6 +446,7 @@ async def get_tasks( :param page_size: :param task_status: :param workflow_run_id: + :param only_standalone_tasks: :return: """ if page < 1: @@ -458,6 +460,8 @@ async def get_tasks( query = query.filter(TaskModel.status.in_(task_status)) if workflow_run_id: query = query.filter(TaskModel.workflow_run_id == workflow_run_id) + if only_standalone_tasks: + query = query.filter(TaskModel.workflow_run_id.is_(None)) query = query.order_by(TaskModel.created_at.desc()).limit(page_size).offset(db_page * page_size) tasks = (await session.scalars(query)).all() return [convert_to_task(task, debug_enabled=self.debug_enabled) for task in tasks] diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.py index b4cc079e5..1a936ac88 100644 --- a/skyvern/forge/sdk/routes/agent_protocol.py +++ b/skyvern/forge/sdk/routes/agent_protocol.py @@ -383,6 +383,7 @@ async def get_agent_tasks( task_status: Annotated[list[TaskStatus] | None, Query()] = None, workflow_run_id: Annotated[str | None, Query()] = None, current_org: Organization = Depends(org_auth_service.get_current_org), + only_standalone_tasks: bool = Query(False), ) -> Response: """ Get all tasks. @@ -390,16 +391,23 @@ async def get_agent_tasks( :param page_size: Page size, defaults to 10 :param task_status: Task status filter :param workflow_run_id: Workflow run id filter + :param only_standalone_tasks: Only standalone tasks, tasks which are part of a workflow run will be filtered out :return: List of tasks with pagination without steps populated. Steps can be populated by calling the get_agent_task endpoint. """ analytics.capture("skyvern-oss-agent-tasks-get") + if only_standalone_tasks and workflow_run_id: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="only_standalone_tasks and workflow_run_id cannot be used together", + ) tasks = await app.DATABASE.get_tasks( page, page_size, task_status=task_status, workflow_run_id=workflow_run_id, organization_id=current_org.organization_id, + only_standalone_tasks=only_standalone_tasks, ) return ORJSONResponse([task.to_task_response().model_dump() for task in tasks])