Skip to content

Commit

Permalink
Pass browser_session_id through async executor
Browse files Browse the repository at this point in the history
  • Loading branch information
satansdeer committed Dec 16, 2024
1 parent 3f0516b commit 6b2077e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions skyvern/forge/sdk/executor/async_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def execute_workflow(
workflow_run_id: str,
max_steps_override: int | None,
api_key: str | None,
browser_session_id: str | None,
**kwargs: dict,
) -> None:
pass
Expand Down Expand Up @@ -93,6 +94,7 @@ async def execute_workflow(
workflow_run_id: str,
max_steps_override: int | None,
api_key: str | None,
browser_session_id: str | None,
**kwargs: dict,
) -> None:
LOG.info(
Expand All @@ -109,4 +111,5 @@ async def execute_workflow(
workflow_run_id=workflow_run_id,
api_key=api_key,
organization=organization,
browser_session_id=browser_session_id,
)
1 change: 1 addition & 0 deletions skyvern/forge/sdk/routes/agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ async def execute_workflow(
organization_id=current_org.organization_id,
workflow_id=workflow_run.workflow_id,
workflow_run_id=workflow_run.workflow_run_id,
browser_session_id=workflow_request.browser_session_id,
max_steps_override=x_max_steps_override,
api_key=x_api_key,
)
Expand Down
21 changes: 19 additions & 2 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,15 @@ async def execute_workflow(
workflow_run_id: str,
api_key: str,
organization: Organization,
browser_session_id: str | None,
) -> WorkflowRun:
"""Execute a workflow."""
organization_id = organization.organization_id
workflow_run = await self.get_workflow_run(workflow_run_id=workflow_run_id)
workflow = await self.get_workflow(workflow_id=workflow_run.workflow_id, organization_id=organization_id)

uses_persistent_browser_state = browser_session_id is not None

# Set workflow run status to running, create workflow run parameters
await self.mark_workflow_run_as_running(workflow_run_id=workflow_run.workflow_run_id)

Expand Down Expand Up @@ -245,6 +248,7 @@ async def execute_workflow(
workflow_run=workflow_run,
api_key=api_key,
need_call_webhook=True,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run
parameters = block.get_all_parameters(workflow_run_id)
Expand Down Expand Up @@ -277,6 +281,7 @@ async def execute_workflow(
workflow_run=workflow_run,
api_key=api_key,
need_call_webhook=False,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run
elif block_result.status == BlockStatus.failed:
Expand All @@ -298,6 +303,7 @@ async def execute_workflow(
workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run

Expand Down Expand Up @@ -332,6 +338,7 @@ async def execute_workflow(
workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run

Expand Down Expand Up @@ -363,7 +370,12 @@ async def execute_workflow(
await self.mark_workflow_run_as_failed(
workflow_run_id=workflow_run.workflow_run_id, failure_reason=failure_reason
)
await self.clean_up_workflow(workflow=workflow, workflow_run=workflow_run, api_key=api_key)
await self.clean_up_workflow(
workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run

refreshed_workflow_run = await app.DATABASE.get_workflow_run(workflow_run_id=workflow_run.workflow_run_id)
Expand All @@ -379,7 +391,12 @@ async def execute_workflow(
workflow_run_id=workflow_run.workflow_run_id,
workflow_run_status=refreshed_workflow_run.status if refreshed_workflow_run else None,
)
await self.clean_up_workflow(workflow=workflow, workflow_run=workflow_run, api_key=api_key)
await self.clean_up_workflow(
workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
close_browser_on_completion=not uses_persistent_browser_state,
)
return workflow_run

async def create_workflow(
Expand Down

0 comments on commit 6b2077e

Please sign in to comment.