feat: migrate workflow use_cache field to generate_script (#3154)

Co-authored-by: devsy-bot <no-reply@devsy.ai>
Co-authored-by: Shuchang Zheng <wintonzheng0325@gmail.com>
This commit is contained in:
devsy-bot[bot]
2025-08-10 09:02:23 -07:00
committed by GitHub
parent 16596e5c61
commit 1a3938a756
13 changed files with 56 additions and 25 deletions

View File

@@ -1363,7 +1363,7 @@ class AgentDB:
version: int | None = None,
is_saved_task: bool = False,
status: WorkflowStatus = WorkflowStatus.published,
use_cache: bool = False,
generate_script: bool = False,
cache_key: str | None = None,
) -> Workflow:
async with self.Session() as session:
@@ -1382,7 +1382,7 @@ class AgentDB:
model=model,
is_saved_task=is_saved_task,
status=status,
use_cache=use_cache,
generate_script=generate_script,
cache_key=cache_key,
)
if workflow_permanent_id:
@@ -1562,7 +1562,7 @@ class AgentDB:
description: str | None = None,
workflow_definition: dict[str, Any] | None = None,
version: int | None = None,
use_cache: bool | None = None,
generate_script: bool | None = None,
cache_key: str | None = None,
) -> Workflow:
try:
@@ -1581,8 +1581,8 @@ class AgentDB:
workflow.workflow_definition = workflow_definition
if version is not None:
workflow.version = version
if use_cache is not None:
workflow.use_cache = use_cache
if generate_script is not None:
workflow.generate_script = generate_script
if cache_key is not None:
workflow.cache_key = cache_key
await session.commit()

View File

@@ -241,7 +241,7 @@ class WorkflowModel(Base):
persist_browser_session = Column(Boolean, default=False, nullable=False)
model = Column(JSON, nullable=True)
status = Column(String, nullable=False, default="published")
use_cache = Column(Boolean, default=False, nullable=False)
generate_script = Column(Boolean, default=False, nullable=False)
cache_key = Column(String, nullable=True)
created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)

View File

@@ -262,7 +262,7 @@ def convert_to_workflow(workflow_model: WorkflowModel, debug_enabled: bool = Fal
deleted_at=workflow_model.deleted_at,
status=WorkflowStatus(workflow_model.status),
extra_http_headers=workflow_model.extra_http_headers,
use_cache=workflow_model.use_cache,
generate_script=workflow_model.generate_script,
cache_key=workflow_model.cache_key,
)

View File

@@ -80,7 +80,7 @@ class Workflow(BaseModel):
status: WorkflowStatus = WorkflowStatus.published
max_screenshot_scrolls: int | None = None
extra_http_headers: dict[str, str] | None = None
use_cache: bool = False
generate_script: bool = False
cache_key: str | None = None
created_at: datetime

View File

@@ -447,5 +447,5 @@ class WorkflowCreateYAMLRequest(BaseModel):
max_screenshot_scrolls: int | None = None
extra_http_headers: dict[str, str] | None = None
status: WorkflowStatus = WorkflowStatus.published
use_cache: bool = False
generate_script: bool = False
cache_key: str | None = None

View File

@@ -621,8 +621,8 @@ class WorkflowService:
organization_id=organization_id,
)
# TODO: generate script for workflow if the workflow.use_cache is True AND there's no script cached for the workflow
if workflow.use_cache:
# generate script for workflow if the workflow.generate_script is True AND there's no script cached for the workflow
if workflow.generate_script:
await self.generate_script_for_workflow(workflow=workflow, workflow_run=workflow_run)
return workflow_run
@@ -645,7 +645,7 @@ class WorkflowService:
is_saved_task: bool = False,
status: WorkflowStatus = WorkflowStatus.published,
extra_http_headers: dict[str, str] | None = None,
use_cache: bool = False,
generate_script: bool = False,
cache_key: str | None = None,
) -> Workflow:
return await app.DATABASE.create_workflow(
@@ -665,7 +665,7 @@ class WorkflowService:
is_saved_task=is_saved_task,
status=status,
extra_http_headers=extra_http_headers,
use_cache=use_cache,
generate_script=generate_script,
cache_key=cache_key,
)
@@ -1548,7 +1548,7 @@ class WorkflowService:
version=existing_version + 1,
is_saved_task=request.is_saved_task,
status=request.status,
use_cache=request.use_cache,
generate_script=request.generate_script,
cache_key=request.cache_key,
)
else:
@@ -1567,7 +1567,7 @@ class WorkflowService:
extra_http_headers=request.extra_http_headers,
is_saved_task=request.is_saved_task,
status=request.status,
use_cache=request.use_cache,
generate_script=request.generate_script,
cache_key=request.cache_key,
)
# Keeping track of the new workflow id to delete it if an error occurs during the creation process
@@ -2334,5 +2334,3 @@ class WorkflowService:
workflow_id=workflow.workflow_id,
workflow_run_id=workflow_run.workflow_run_id,
)
return