mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 23:18:05 +08:00
feat(trigger): enhance trigger subscription management and cache handling
- Added `name` parameter to `TriggerSubscriptionBuilderCreateApi` for better subscription identification. - Implemented `delete_cache_for_subscription` function to clear cache associated with trigger subscriptions. - Updated `WorkflowPluginTriggerService` to check for existing subscriptions before creating new plugin triggers, improving error handling. - Refactored `TriggerProviderService` to utilize the new cache deletion method during provider deletion. This improves the overall management of trigger subscriptions and enhances cache efficiency.
This commit is contained in:
@ -5,6 +5,7 @@ from sqlalchemy.orm import Session
|
||||
from werkzeug.exceptions import BadRequest, NotFound
|
||||
|
||||
from extensions.ext_database import db
|
||||
from models.trigger import TriggerSubscription
|
||||
from models.workflow import WorkflowPluginTrigger
|
||||
|
||||
|
||||
@ -53,6 +54,16 @@ class WorkflowPluginTriggerService:
|
||||
if existing_trigger:
|
||||
raise BadRequest("Plugin trigger already exists for this app and node")
|
||||
|
||||
# Check if subscription exists
|
||||
subscription = session.scalar(
|
||||
select(TriggerSubscription).where(
|
||||
TriggerSubscription.id == subscription_id,
|
||||
)
|
||||
)
|
||||
|
||||
if not subscription:
|
||||
raise BadRequest("Subscription not found")
|
||||
|
||||
# Create new plugin trigger
|
||||
plugin_trigger = WorkflowPluginTrigger(
|
||||
app_id=app_id,
|
||||
@ -340,7 +351,7 @@ class WorkflowPluginTriggerService:
|
||||
)
|
||||
|
||||
if not plugin_trigger:
|
||||
raise NotFound("Plugin trigger not found")
|
||||
return
|
||||
|
||||
session.delete(plugin_trigger)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user