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:
Harry
2025-09-05 14:22:20 +08:00
parent 81ef7343d4
commit 0371d71409
5 changed files with 34 additions and 11 deletions

View File

@ -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)