refactor: confused abstract class

This commit is contained in:
Yeuoly 2025-10-18 19:47:23 +08:00
parent b6b433626e
commit 3a18337129
2 changed files with 6 additions and 30 deletions

View File

@ -51,7 +51,7 @@ class PluginTriggerDebugEventPoller(TriggerDebugEventPoller):
provider_id = TriggerProviderID(plugin_trigger_data.provider_id)
pool_key: str = PluginTriggerDebugEvent.build_pool_key(
name=plugin_trigger_data.event_name,
provider_id=provider_id,
provider_id=str(provider_id),
tenant_id=self.tenant_id,
subscription_id=plugin_trigger_data.subscription_id,
)

View File

@ -1,28 +1,14 @@
from abc import ABC, abstractmethod
from collections.abc import Mapping
from typing import Any
from pydantic import BaseModel, Field
class BaseDebugEvent(ABC, BaseModel):
class BaseDebugEvent(BaseModel):
"""Base class for all debug events."""
timestamp: int
@classmethod
@abstractmethod
def build_pool_key(cls, **kwargs: Any) -> str:
"""
Generate the waiting pool key for this event type.
Each subclass implements its own pool key strategy based on routing parameters.
Returns:
Redis key for the waiting pool
"""
raise NotImplementedError("Subclasses must implement build_pool_key")
class ScheduleDebugEvent(BaseDebugEvent):
"""Debug event for schedule triggers."""
@ -31,7 +17,7 @@ class ScheduleDebugEvent(BaseDebugEvent):
inputs: Mapping[str, Any]
@classmethod
def build_pool_key(cls, **kwargs: Any) -> str:
def build_pool_key(cls, tenant_id: str, app_id: str, node_id: str) -> str:
"""Generate pool key for schedule events.
Args:
@ -39,9 +25,6 @@ class ScheduleDebugEvent(BaseDebugEvent):
app_id: App ID
node_id: Node ID
"""
tenant_id = kwargs["tenant_id"]
app_id = kwargs["app_id"]
node_id = kwargs["node_id"]
return f"schedule_trigger_debug_waiting_pool:{tenant_id}:{app_id}:{node_id}"
@ -53,7 +36,7 @@ class WebhookDebugEvent(BaseDebugEvent):
payload: dict[str, Any] = Field(default_factory=dict)
@classmethod
def build_pool_key(cls, **kwargs: Any) -> str:
def build_pool_key(cls, tenant_id: str, app_id: str, node_id: str) -> str:
"""Generate pool key for webhook events.
Args:
@ -61,9 +44,6 @@ class WebhookDebugEvent(BaseDebugEvent):
app_id: App ID
node_id: Node ID
"""
tenant_id = kwargs["tenant_id"]
app_id = kwargs["app_id"]
node_id = kwargs["node_id"]
return f"webhook_trigger_debug_waiting_pool:{tenant_id}:{app_id}:{node_id}"
@ -77,7 +57,7 @@ class PluginTriggerDebugEvent(BaseDebugEvent):
provider_id: str
@classmethod
def build_pool_key(cls, **kwargs: Any) -> str:
def build_pool_key(cls, tenant_id: str, provider_id: str, subscription_id: str, name: str) -> str:
"""Generate pool key for plugin trigger events.
Args:
@ -86,8 +66,4 @@ class PluginTriggerDebugEvent(BaseDebugEvent):
provider_id: Provider ID
subscription_id: Subscription ID
"""
tenant_id = kwargs["tenant_id"]
provider_id = kwargs["provider_id"]
subscription_id = kwargs["subscription_id"]
event_name = kwargs["name"]
return f"plugin_trigger_debug_waiting_pool:{tenant_id}:{str(provider_id)}:{subscription_id}:{event_name}"
return f"plugin_trigger_debug_waiting_pool:{tenant_id}:{str(provider_id)}:{subscription_id}:{name}"