-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a runs endpoint that can return workflow runs or tasks #1708
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,24 @@ async def get_agent_tasks( | |
return ORJSONResponse([(await app.agent.build_task_response(task=task)).model_dump() for task in tasks]) | ||
|
||
|
||
@base_router.get("/runs", response_model=list[WorkflowRun | Task]) | ||
@base_router.get("/runs/", response_model=list[WorkflowRun | Task], include_in_schema=False) | ||
async def get_runs( | ||
current_org: Organization = Depends(org_auth_service.get_current_org), | ||
page: int = Query(1, ge=1), | ||
page_size: int = Query(10, ge=1), | ||
status: Annotated[list[WorkflowRunStatus] | None, Query()] = None, | ||
) -> Response: | ||
analytics.capture("skyvern-oss-agent-runs-get") | ||
|
||
# temporary limit to 100 runs | ||
if page > 10: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temporary limit: returning an empty list when page > 10 may surprise clients. Consider returning an HTTP error or a more informative response. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid duplicating the temporary page limit check. Both get_runs endpoint and get_all_runs DB method check if page > 10. Consider unifying this logic. |
||
return [] | ||
|
||
runs = await app.DATABASE.get_all_runs(current_org.organization_id, page=page, page_size=page_size, status=status) | ||
return ORJSONResponse([run.model_dump() for run in runs]) | ||
|
||
|
||
@base_router.get("/internal/tasks", tags=["agent"], response_model=list[Task]) | ||
@base_router.get( | ||
"/internal/tasks/", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_all_runs method retrieves page*page_size records from two separate queries, merges, sorts in Python, and then slices the result. This can be inefficient for large datasets. Consider handling pagination at the database level.