mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2025-09-10 23:44:36 +00:00
workflow runtime API (#1421)
This commit is contained in:
parent
2e37542218
commit
94a3779bd7
5 changed files with 137 additions and 79 deletions
|
@ -25,6 +25,7 @@ from skyvern.forge.sdk.db.enums import TaskType
|
|||
from skyvern.forge.sdk.models import Step
|
||||
from skyvern.forge.sdk.schemas.organizations import Organization
|
||||
from skyvern.forge.sdk.schemas.tasks import ProxyLocation, Task
|
||||
from skyvern.forge.sdk.schemas.workflow_runs import WorkflowRunBlock, WorkflowRunTimeline, WorkflowRunTimelineType
|
||||
from skyvern.forge.sdk.workflow.exceptions import (
|
||||
ContextParameterSourceNotDefined,
|
||||
InvalidWaitBlockTime,
|
||||
|
@ -1602,3 +1603,48 @@ class WorkflowService:
|
|||
organization=organization,
|
||||
request=workflow_create_request,
|
||||
)
|
||||
|
||||
async def get_workflow_run_timeline(
|
||||
self,
|
||||
workflow_run_id: str,
|
||||
organization_id: str | None = None,
|
||||
) -> list[WorkflowRunTimeline]:
|
||||
"""
|
||||
build the tree structure of the workflow run timeline
|
||||
"""
|
||||
workflow_run_blocks = await app.DATABASE.get_workflow_run_blocks(
|
||||
workflow_run_id=workflow_run_id,
|
||||
organization_id=organization_id,
|
||||
)
|
||||
# get all the actions for all workflow run blocks
|
||||
task_ids = [block.task_id for block in workflow_run_blocks if block.task_id]
|
||||
task_id_to_block: dict[str, WorkflowRunBlock] = {
|
||||
block.task_id: block for block in workflow_run_blocks if block.task_id
|
||||
}
|
||||
actions = await app.DATABASE.get_tasks_actions(task_ids=task_ids, organization_id=organization_id)
|
||||
for action in actions:
|
||||
if not action.task_id:
|
||||
continue
|
||||
task_block = task_id_to_block[action.task_id]
|
||||
task_block.actions.append(action)
|
||||
|
||||
result = []
|
||||
block_map: dict[str, WorkflowRunTimeline] = {}
|
||||
while workflow_run_blocks:
|
||||
block = workflow_run_blocks.pop(0)
|
||||
workflow_run_timeline = WorkflowRunTimeline(
|
||||
type=WorkflowRunTimelineType.block,
|
||||
block=block,
|
||||
created_at=block.created_at,
|
||||
modified_at=block.modified_at,
|
||||
)
|
||||
if block.parent_workflow_run_block_id:
|
||||
if block.parent_workflow_run_block_id in block_map:
|
||||
block_map[block.parent_workflow_run_block_id].children.append(workflow_run_timeline)
|
||||
else:
|
||||
# put the block back to the queue
|
||||
workflow_run_blocks.append(block)
|
||||
else:
|
||||
result.append(workflow_run_timeline)
|
||||
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue