sequential workflow fix (#3473)

This commit is contained in:
LawyZheng
2025-09-19 10:17:52 +08:00
committed by GitHub
parent 82b2187583
commit fffac33649

View File

@@ -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,