feat(trigger): refactor trigger debug event handling and improve response structures

- Renamed and refactored trigger debug event classes to enhance clarity and consistency, including changes from `TriggerDebugEventData` to `TriggerEventData` and related response classes.
- Updated `DraftWorkflowTriggerNodeApi` and `DraftWorkflowTriggerRunApi` to utilize the new event structures, improving the handling of trigger events.
- Removed the `TriggerDebugEventGenerator` class, consolidating event generation directly within the API logic for streamlined processing.
- Enhanced error handling and response formatting for trigger events, ensuring structured outputs for better integration and debugging.

This refactor improves the overall architecture of trigger debugging, making it more intuitive and maintainable.
This commit is contained in:
Harry
2025-09-11 16:55:38 +08:00
parent c3ebb22a4b
commit 57c0bc9fb6
9 changed files with 102 additions and 176 deletions

View File

@ -64,25 +64,22 @@ class TriggerProviderService:
.all()
)
subscriptions = [subscription.to_api_entity() for subscription in subscriptions_db]
# Get distinct app count for each subscription
if subscriptions:
usage_counts = (
session.query(
WorkflowPluginTrigger.subscription_id,
func.count(func.distinct(WorkflowPluginTrigger.app_id)).label("app_count"),
)
.filter(
WorkflowPluginTrigger.tenant_id == tenant_id,
WorkflowPluginTrigger.subscription_id.in_([s.id for s in subscriptions]),
)
.group_by(WorkflowPluginTrigger.subscription_id)
.all()
if not subscriptions:
return []
usage_counts = (
session.query(
WorkflowPluginTrigger.subscription_id,
func.count(func.distinct(WorkflowPluginTrigger.app_id)).label("app_count"),
)
# Convert query result to dictionary: subscription_id -> distinct app count
workflows_in_use_map = {str(row.subscription_id): int(row.app_count) for row in usage_counts}
.filter(
WorkflowPluginTrigger.tenant_id == tenant_id,
WorkflowPluginTrigger.subscription_id.in_([s.id for s in subscriptions]),
)
.group_by(WorkflowPluginTrigger.subscription_id)
.all()
)
workflows_in_use_map = {str(row.subscription_id): int(row.app_count) for row in usage_counts}
# Process subscriptions and mask credentials
provider_controller = TriggerManager.get_trigger_provider(tenant_id, provider_id)
for subscription in subscriptions:
encrypter, _ = create_trigger_provider_encrypter_for_subscription(
@ -91,7 +88,6 @@ class TriggerProviderService:
subscription=subscription,
)
subscription.credentials = encrypter.mask_credentials(subscription.credentials)
# Set workflows_in_use count, default to 0 if not found
count = workflows_in_use_map.get(subscription.id)
subscription.workflows_in_use = count if count is not None else 0