Add workflow_run_id filter to get tasks endpoint (#571)
This commit is contained in:
@@ -414,12 +414,15 @@ class AgentDB:
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
task_status: list[TaskStatus] | None = None,
|
||||
workflow_run_id: str | None = None,
|
||||
organization_id: str | None = None,
|
||||
) -> list[Task]:
|
||||
"""
|
||||
Get all tasks.
|
||||
:param page: Starts at 1
|
||||
:param page_size:
|
||||
:param task_status:
|
||||
:param workflow_run_id:
|
||||
:return:
|
||||
"""
|
||||
if page < 1:
|
||||
@@ -428,9 +431,11 @@ class AgentDB:
|
||||
try:
|
||||
async with self.Session() as session:
|
||||
db_page = page - 1 # offset logic is 0 based
|
||||
query = select(TaskModel).filter_by(organization_id=organization_id)
|
||||
query = select(TaskModel).filter(TaskModel.organization_id == organization_id)
|
||||
if task_status:
|
||||
query = query.filter(TaskModel.status.in_(task_status))
|
||||
if workflow_run_id:
|
||||
query = query.filter(TaskModel.workflow_run_id == workflow_run_id)
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user