Jon/allow block scripts to be fetched with status (#3469)
This commit is contained in:
@@ -107,7 +107,7 @@ from skyvern.forge.sdk.workflow.models.workflow import (
|
||||
WorkflowRunStatus,
|
||||
)
|
||||
from skyvern.schemas.runs import ProxyLocation, RunEngine, RunType
|
||||
from skyvern.schemas.scripts import Script, ScriptBlock, ScriptFile
|
||||
from skyvern.schemas.scripts import Script, ScriptBlock, ScriptFile, ScriptStatus
|
||||
from skyvern.schemas.steps import AgentStepOutput
|
||||
from skyvern.schemas.workflows import BlockStatus, BlockType, WorkflowStatus
|
||||
from skyvern.webeye.actions.actions import Action
|
||||
@@ -4088,6 +4088,7 @@ class AgentDB:
|
||||
workflow_permanent_id: str,
|
||||
cache_key_value: str,
|
||||
cache_key: str | None = None,
|
||||
statuses: list[ScriptStatus] | None = None,
|
||||
) -> list[Script]:
|
||||
"""Get latest script versions linked to a workflow by a specific cache_key_value."""
|
||||
try:
|
||||
@@ -4104,6 +4105,9 @@ class AgentDB:
|
||||
if cache_key is not None:
|
||||
ws_script_ids_subquery = ws_script_ids_subquery.where(WorkflowScriptModel.cache_key == cache_key)
|
||||
|
||||
if statuses is not None and len(statuses) > 0:
|
||||
ws_script_ids_subquery = ws_script_ids_subquery.where(WorkflowScriptModel.status.in_(statuses))
|
||||
|
||||
# Latest version per script_id within the org and not deleted
|
||||
latest_versions_subquery = (
|
||||
select(
|
||||
|
||||
@@ -295,12 +295,14 @@ async def get_workflow_script_blocks(
|
||||
raise HTTPException(status_code=404, detail="Workflow not found")
|
||||
|
||||
cache_key = block_script_request.cache_key or workflow.cache_key or ""
|
||||
status = block_script_request.status
|
||||
|
||||
scripts = await app.DATABASE.get_workflow_scripts_by_cache_key_value(
|
||||
organization_id=current_org.organization_id,
|
||||
workflow_permanent_id=workflow_permanent_id,
|
||||
cache_key_value=cache_key_value,
|
||||
cache_key=cache_key,
|
||||
statuses=[status] if status else None,
|
||||
)
|
||||
|
||||
if not scripts:
|
||||
|
||||
@@ -154,6 +154,7 @@ class ScriptBlocksResponse(BaseModel):
|
||||
class ScriptBlocksRequest(BaseModel):
|
||||
cache_key_value: str
|
||||
cache_key: str | None = None
|
||||
status: ScriptStatus | None = None
|
||||
|
||||
|
||||
class ScriptStatus(StrEnum):
|
||||
|
||||
Reference in New Issue
Block a user