refactor(sqlalchemy_workflow_node_execution_repository): Refactors repository initialization and imports

Signed-off-by: -LAN- <laipz8200@outlook.com>
pull/19430/head
-LAN- 1 year ago
parent d2daa1367b
commit 79e1f74fc4
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF

@ -44,8 +44,8 @@ class SQLAlchemyWorkflowNodeExecutionRepository(WorkflowNodeExecutionRepository)
self, self,
session_factory: sessionmaker | Engine, session_factory: sessionmaker | Engine,
user: Union[Account, EndUser], user: Union[Account, EndUser],
app_id: Optional[str] = None, app_id: Optional[str],
triggered_from: Optional[WorkflowNodeExecutionTriggeredFrom] = None, triggered_from: Optional[WorkflowNodeExecutionTriggeredFrom],
): ):
""" """
Initialize the repository with a SQLAlchemy sessionmaker or engine and context information. Initialize the repository with a SQLAlchemy sessionmaker or engine and context information.
@ -53,8 +53,8 @@ class SQLAlchemyWorkflowNodeExecutionRepository(WorkflowNodeExecutionRepository)
Args: Args:
session_factory: SQLAlchemy sessionmaker or engine for creating sessions session_factory: SQLAlchemy sessionmaker or engine for creating sessions
user: Account or EndUser object containing tenant_id, user ID, and role information user: Account or EndUser object containing tenant_id, user ID, and role information
app_id: Optional app ID for filtering by application app_id: App ID for filtering by application (can be None)
triggered_from: Source of the execution trigger (single-step or workflow-run) triggered_from: Source of the execution trigger (SINGLE_STEP or WORKFLOW_RUN)
""" """
# If an engine is provided, create a sessionmaker from it # If an engine is provided, create a sessionmaker from it
if isinstance(session_factory, Engine): if isinstance(session_factory, Engine):

@ -7,7 +7,14 @@ from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository
from core.workflow.repository.workflow_node_execution_repository import OrderConfig from core.workflow.repository.workflow_node_execution_repository import OrderConfig
from extensions.ext_database import db from extensions.ext_database import db
from libs.infinite_scroll_pagination import InfiniteScrollPagination from libs.infinite_scroll_pagination import InfiniteScrollPagination
from models import Account, App, EndUser, WorkflowNodeExecution, WorkflowRun, WorkflowRunTriggeredFrom from models import (
Account,
App,
EndUser,
WorkflowNodeExecution,
WorkflowRun,
WorkflowRunTriggeredFrom,
)
class WorkflowRunService: class WorkflowRunService:
@ -130,7 +137,10 @@ class WorkflowRunService:
return [] return []
repository = SQLAlchemyWorkflowNodeExecutionRepository( repository = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=db.engine, user=user, app_id=app_model.id session_factory=db.engine,
user=user,
app_id=app_model.id,
triggered_from=None,
) )
# Use the repository to get the node executions with ordering # Use the repository to get the node executions with ordering

@ -204,7 +204,12 @@ def _delete_app_workflow_node_executions(tenant_id: str, app_id: str):
raise ValueError(errmsg) raise ValueError(errmsg)
# Create a repository instance for WorkflowNodeExecution # Create a repository instance for WorkflowNodeExecution
repository = SQLAlchemyWorkflowNodeExecutionRepository(session_factory=db.engine, user=user, app_id=app_id) repository = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=db.engine,
user=user,
app_id=app_id,
triggered_from=None,
)
# Use the clear method to delete all records for this tenant_id and app_id # Use the clear method to delete all records for this tenant_id and app_id
repository.clear() repository.clear()

@ -58,7 +58,12 @@ def repository(session, mock_user):
"""Create a repository instance with test data.""" """Create a repository instance with test data."""
_, session_factory = session _, session_factory = session
app_id = "test-app" app_id = "test-app"
return SQLAlchemyWorkflowNodeExecutionRepository(session_factory=session_factory, user=mock_user, app_id=app_id) return SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=session_factory,
user=mock_user,
app_id=app_id,
triggered_from=None,
)
def test_save(repository, session): def test_save(repository, session):

Loading…
Cancel
Save