Skip to content

Automate browser based workflows with AI

sequential workflow fix (#3473)

LawyZhengfffac3364943
diff --git a/skyvern/forge/sdk/db/client.py b/skyvern/forge/sdk/db/client.py
index 161207e12..7a1f224d1 100644
--- a/skyvern/forge/sdk/db/client.py
+++ b/skyvern/forge/sdk/db/client.py
@@ -1786,6 +1786,27 @@ class AgentDB:
LOG.error("SQLAlchemyError", exc_info=True)
raise
+ async def get_last_running_workflow_run(
+ self,
+ workflow_permanent_id: str,
+ organization_id: str | None = None,
+ ) -> WorkflowRun | None:
+ try:
+ async with self.Session() as session:
+ query = select(WorkflowRunModel).filter_by(workflow_permanent_id=workflow_permanent_id)
+ if organization_id:
+ query = query.filter_by(organization_id=organization_id)
+ query = query.filter_by(status=WorkflowRunStatus.running)
+ query = query.filter(
+ WorkflowRunModel.started_at.isnot(None)
+ ) # filter out workflow runs that does not have a started_at timestamp
+ query = query.order_by(WorkflowRunModel.started_at.desc())
+ workflow_run = (await session.scalars(query)).first()
+ return convert_to_workflow_run(workflow_run) if workflow_run else None
+ except SQLAlchemyError:
+ LOG.error("SQLAlchemyError", exc_info=True)
+ raise
+
async def get_workflow_runs(
self,
organization_id: str,