mirror of
https://github.com/langgenius/dify.git
synced 2026-03-31 02:48:49 +08:00
refactor(trigger): unify debug event handling and improve polling mechanism
- Introduced a base class for debug events to streamline event handling. - Refactored `TriggerDebugService` to support multiple event types through a generic dispatch/poll interface. - Updated webhook and plugin trigger debug services to utilize the new event structure. - Enhanced the dispatch logic in `dispatch_triggered_workflows_async` to accommodate the new event model.
This commit is contained in:
@ -15,7 +15,7 @@ from extensions.ext_database import db
|
||||
from extensions.ext_storage import storage
|
||||
from models.provider_ids import TriggerProviderID
|
||||
from models.trigger import TriggerSubscription
|
||||
from services.trigger.trigger_debug_service import TriggerDebugService
|
||||
from services.trigger.trigger_debug_service import PluginTriggerDebugEvent, TriggerDebugService
|
||||
from services.trigger.trigger_service import TriggerService
|
||||
from services.workflow.entities import PluginTriggerDispatchData
|
||||
|
||||
@ -114,13 +114,23 @@ def dispatch_triggered_workflows_async(
|
||||
# Dispatch to debug sessions after processing all triggers
|
||||
debug_dispatched = 0
|
||||
try:
|
||||
debug_dispatched = TriggerDebugService.dispatch_debug_event(
|
||||
tenant_id=subscription.tenant_id,
|
||||
subscription_id=subscription_id,
|
||||
events=events,
|
||||
timestamp=timestamp,
|
||||
request_id=request_id,
|
||||
)
|
||||
for event_name in events:
|
||||
pool_key: str = PluginTriggerDebugEvent.build_pool_key(
|
||||
tenant_id=subscription.tenant_id,
|
||||
subscription_id=subscription_id,
|
||||
trigger_name=event_name,
|
||||
)
|
||||
event = PluginTriggerDebugEvent(
|
||||
subscription_id=subscription_id,
|
||||
request_id=request_id,
|
||||
timestamp=timestamp,
|
||||
event_name=event_name,
|
||||
)
|
||||
debug_dispatched += TriggerDebugService.dispatch(
|
||||
tenant_id=subscription.tenant_id,
|
||||
event=event,
|
||||
pool_key=pool_key,
|
||||
)
|
||||
except Exception:
|
||||
# Silent failure for debug dispatch
|
||||
logger.exception("Failed to dispatch to debug sessions")
|
||||
|
||||
Reference in New Issue
Block a user