Skip to content

Commit

Permalink
🔄 synced local 'skyvern/' with remote 'skyvern/'
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->

> [!IMPORTANT]
> Add `workflow_title` to `WorkflowRun` and update related functions to handle this new field.
>
>   - **Behavior**:
>     - Add `workflow_title` to `WorkflowRun` in `workflow.py` and `WorkflowRunStatusResponse`.
>     - Update `get_all_runs()`, `get_workflow_runs()`, and `get_workflow_runs_for_workflow_permanent_id()` in `client.py` to include `workflow_title`.
>     - Modify `convert_to_workflow_run()` in `utils.py` to accept `workflow_title`.
>     - Update `build_workflow_run_status_response()` in `service.py` to include `workflow_title` in the response.
>   - **Models**:
>     - Add `workflow_title` field to `WorkflowRun` and `WorkflowRunStatusResponse` in `workflow.py`.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=Skyvern-AI%2Fskyvern-cloud&utm_source=github&utm_medium=referral)<sup> for 4e74b86fc6c29ab8221e35acfe2967acf7e3f89e. It will automatically update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
wintonzheng committed Feb 5, 2025
1 parent cc449dc commit bc9edd2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
33 changes: 23 additions & 10 deletions skyvern/forge/sdk/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,15 +1398,18 @@ async def get_all_runs(

limit = page * page_size

workflow_run_query = select(WorkflowRunModel).filter(
WorkflowRunModel.organization_id == organization_id
workflow_run_query = (
select(WorkflowRunModel, WorkflowModel.title)
.join(WorkflowModel, WorkflowModel.workflow_id == WorkflowRunModel.workflow_id)
.filter(WorkflowRunModel.organization_id == organization_id)
)
if status:
workflow_run_query = workflow_run_query.filter(WorkflowRunModel.status.in_(status))
workflow_run_query = workflow_run_query.order_by(WorkflowRunModel.created_at.desc()).limit(limit)
workflow_run_query_result = (await session.scalars(workflow_run_query)).all()
workflow_run_query_result = (await session.execute(workflow_run_query)).all()
workflow_runs = [
convert_to_workflow_run(run, debug_enabled=self.debug_enabled) for run in workflow_run_query_result
convert_to_workflow_run(run, workflow_title=title, debug_enabled=self.debug_enabled)
for run, title in workflow_run_query_result
]

task_query = (
Expand Down Expand Up @@ -1453,15 +1456,19 @@ async def get_workflow_runs(
async with self.Session() as session:
db_page = page - 1 # offset logic is 0 based
query = (
select(WorkflowRunModel)
select(WorkflowRunModel, WorkflowModel.title)
.join(WorkflowModel, WorkflowModel.workflow_id == WorkflowRunModel.workflow_id)
.filter(WorkflowRunModel.organization_id == organization_id)
.filter(WorkflowRunModel.parent_workflow_run_id.is_(None))
)
if status:
query = query.filter(WorkflowRunModel.status.in_(status))
query = query.order_by(WorkflowRunModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
workflow_runs = (await session.scalars(query)).all()
return [convert_to_workflow_run(run) for run in workflow_runs]
workflow_runs = (await session.execute(query)).all()
return [
convert_to_workflow_run(run, workflow_title=title, debug_enabled=self.debug_enabled)
for run, title in workflow_runs
]
except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
raise
Expand All @@ -1478,15 +1485,21 @@ async def get_workflow_runs_for_workflow_permanent_id(
async with self.Session() as session:
db_page = page - 1 # offset logic is 0 based
query = (
select(WorkflowRunModel)
select(WorkflowRunModel, WorkflowModel.title)
.join(WorkflowModel, WorkflowModel.workflow_id == WorkflowRunModel.workflow_id)
.filter(WorkflowRunModel.workflow_permanent_id == workflow_permanent_id)
.filter(WorkflowRunModel.organization_id == organization_id)
)
if status:
query = query.filter(WorkflowRunModel.status.in_(status))
query = query.order_by(WorkflowRunModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
workflow_runs = (await session.scalars(query)).all()
return [convert_to_workflow_run(run) for run in workflow_runs]
workflow_runs_and_titles_tuples = (await session.execute(query)).all()
workflow_runs = [
convert_to_workflow_run(run, workflow_title=title, debug_enabled=self.debug_enabled)
for run, title in workflow_runs_and_titles_tuples
]
return workflow_runs

except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
raise
Expand Down
5 changes: 4 additions & 1 deletion skyvern/forge/sdk/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def convert_to_workflow(workflow_model: WorkflowModel, debug_enabled: bool = Fal
)


def convert_to_workflow_run(workflow_run_model: WorkflowRunModel, debug_enabled: bool = False) -> WorkflowRun:
def convert_to_workflow_run(
workflow_run_model: WorkflowRunModel, workflow_title: str | None = None, debug_enabled: bool = False
) -> WorkflowRun:
if debug_enabled:
LOG.debug(
"Converting WorkflowRunModel to WorkflowRun",
Expand All @@ -215,6 +217,7 @@ def convert_to_workflow_run(workflow_run_model: WorkflowRunModel, debug_enabled:
totp_identifier=workflow_run_model.totp_identifier,
created_at=workflow_run_model.created_at,
modified_at=workflow_run_model.modified_at,
workflow_title=workflow_title,
)


Expand Down
2 changes: 2 additions & 0 deletions skyvern/forge/sdk/workflow/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class WorkflowRun(BaseModel):
totp_identifier: str | None = None
failure_reason: str | None = None
parent_workflow_run_id: str | None = None
workflow_title: str | None = None

created_at: datetime
modified_at: datetime
Expand Down Expand Up @@ -147,3 +148,4 @@ class WorkflowRunStatusResponse(BaseModel):
total_steps: int | None = None
total_cost: float | None = None
observer_task: ObserverTask | None = None
workflow_title: str | None = None
1 change: 1 addition & 0 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ async def build_workflow_run_status_response(
outputs=outputs,
total_steps=total_steps,
total_cost=total_cost,
workflow_title=workflow.title,
)

async def clean_up_workflow(
Expand Down

0 comments on commit bc9edd2

Please sign in to comment.