mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
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:
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user