Skip to content

Commit

Permalink
fix: delete tool parameters cache when sync draft workflow for run wo…
Browse files Browse the repository at this point in the history
…rkflow use new parameter change in draft workflow (langgenius#3637)
  • Loading branch information
gaoxin-pen authored Apr 22, 2024
1 parent a11a158 commit c4509b9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/events/app_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

# sender: app, kwargs: published_workflow
app_published_workflow_was_updated = signal('app-published-workflow-was-updated')

# sender: app, kwargs: synced_draft_workflow
app_draft_workflow_was_synced = signal('app-draft-workflow-was-synced')
1 change: 1 addition & 0 deletions api/events/event_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .create_site_record_when_app_created import handle
from .deduct_quota_when_messaeg_created import handle
from .delete_installed_app_when_app_deleted import handle
from .delete_tool_parameters_cache_when_sync_draft_workflow import handle
from .update_app_dataset_join_when_app_model_config_updated import handle
from .update_app_dataset_join_when_app_published_workflow_updated import handle
from .update_provider_last_used_at_when_messaeg_created import handle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from core.tools.tool_manager import ToolManager
from core.tools.utils.configuration import ToolParameterConfigurationManager
from core.workflow.entities.node_entities import NodeType
from core.workflow.nodes.tool.entities import ToolEntity
from events.app_event import app_draft_workflow_was_synced


@app_draft_workflow_was_synced.connect
def handle(sender, **kwargs):
app = sender
for node_data in kwargs.get('synced_draft_workflow').graph_dict.get('nodes', []):
if node_data.get('data', {}).get('type') == NodeType.TOOL.value:
tool_entity = ToolEntity(**node_data["data"])
tool_runtime = ToolManager.get_tool_runtime(
provider_type=tool_entity.provider_type,
provider_name=tool_entity.provider_id,
tool_name=tool_entity.tool_name,
tenant_id=app.tenant_id,
)
manager = ToolParameterConfigurationManager(
tenant_id=app.tenant_id,
tool_runtime=tool_runtime,
provider_name=tool_entity.provider_name,
provider_type=tool_entity.provider_type,
)
manager.delete_tool_parameters_cache()
5 changes: 4 additions & 1 deletion api/services/workflow_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from core.workflow.entities.node_entities import NodeType
from core.workflow.errors import WorkflowNodeRunFailedError
from core.workflow.workflow_engine_manager import WorkflowEngineManager
from events.app_event import app_published_workflow_was_updated
from events.app_event import app_draft_workflow_was_synced, app_published_workflow_was_updated
from extensions.ext_database import db
from models.account import Account
from models.model import App, AppMode
Expand Down Expand Up @@ -98,6 +98,9 @@ def sync_draft_workflow(self, app_model: App,
# commit db session changes
db.session.commit()

# trigger app workflow events
app_draft_workflow_was_synced.send(app_model, synced_draft_workflow=workflow)

# return draft workflow
return workflow

Expand Down

0 comments on commit c4509b9

Please sign in to comment.