browser session sequential workflow run (#4181)

This commit is contained in:
LawyZheng
2025-12-04 00:25:35 +08:00
committed by GitHub
parent 53e994c28b
commit d3c1e744c9
3 changed files with 61 additions and 29 deletions

View File

@@ -2518,6 +2518,7 @@ class AgentDB:
try:
async with self.Session() as session:
query = select(WorkflowRunModel).filter_by(workflow_permanent_id=workflow_permanent_id)
query = query.filter(WorkflowRunModel.browser_session_id.is_(None))
if organization_id:
query = query.filter_by(organization_id=organization_id)
query = query.filter_by(status=WorkflowRunStatus.queued)
@@ -2558,6 +2559,7 @@ class AgentDB:
try:
async with self.Session() as session:
query = select(WorkflowRunModel).filter_by(workflow_permanent_id=workflow_permanent_id)
query = query.filter(WorkflowRunModel.browser_session_id.is_(None))
if organization_id:
query = query.filter_by(organization_id=organization_id)
query = query.filter_by(status=WorkflowRunStatus.running)
@@ -2573,6 +2575,36 @@ class AgentDB:
LOG.error("SQLAlchemyError", exc_info=True)
raise
async def get_last_workflow_run_for_browser_session(
self,
browser_session_id: str,
organization_id: str | None = None,
) -> WorkflowRun | None:
try:
async with self.Session() as session:
# check if there's a queued run
query = select(WorkflowRunModel).filter_by(browser_session_id=browser_session_id)
if organization_id:
query = query.filter_by(organization_id=organization_id)
queue_query = query.filter_by(status=WorkflowRunStatus.queued)
queue_query = queue_query.order_by(WorkflowRunModel.modified_at.desc())
workflow_run = (await session.scalars(queue_query)).first()
if workflow_run:
return convert_to_workflow_run(workflow_run)
# check if there's a running run
running_query = query.filter_by(status=WorkflowRunStatus.running)
running_query = running_query.filter(WorkflowRunModel.started_at.isnot(None))
running_query = running_query.order_by(WorkflowRunModel.started_at.desc())
workflow_run = (await session.scalars(running_query)).first()
if workflow_run:
return convert_to_workflow_run(workflow_run)
return None
except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
raise
async def get_workflows_depending_on(
self,
workflow_run_id: str,