Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore(api): convert BaseQueueDispatcher from ABC to Protocol (#37200)

Eric Caof948e442e003
diff --git a/api/services/workflow/queue_dispatcher.py b/api/services/workflow/queue_dispatcher.py
index 1a79958cc2d..0944b20357e 100644
--- a/api/services/workflow/queue_dispatcher.py
+++ b/api/services/workflow/queue_dispatcher.py
@@ -1,13 +1,12 @@
-from typing import override
+from typing import Protocol, override
"""
Queue dispatcher system for async workflow execution.
-Implements an ABC-based pattern for handling different subscription tiers
+Implements a Protocol-based pattern for handling different subscription tiers
with appropriate queue routing and priority assignment.
"""
-from abc import ABC, abstractmethod
from enum import StrEnum
from configs import dify_config
@@ -22,18 +21,16 @@ class QueuePriority(StrEnum):
SANDBOX = "workflow_sandbox" # Free tier
-class BaseQueueDispatcher(ABC):
- """Abstract base class for queue dispatchers"""
+class BaseQueueDispatcher(Protocol):
+ """Protocol for queue dispatchers"""
- @abstractmethod
def get_queue_name(self) -> str:
"""Get the queue name for this dispatcher"""
- pass
+ ...
- @abstractmethod
def get_priority(self) -> int:
"""Get task priority level"""
- pass
+ ...
class ProfessionalQueueDispatcher(BaseQueueDispatcher):
diff --git a/api/tests/unit_tests/services/workflow/test_queue_dispatcher.py b/api/tests/unit_tests/services/workflow/test_queue_dispatcher.py
index bbfc1cc294e..18b46e40f52 100644
--- a/api/tests/unit_tests/services/workflow/test_queue_dispatcher.py
+++ b/api/tests/unit_tests/services/workflow/test_queue_dispatcher.py
@@ -1,9 +1,6 @@
from unittest.mock import patch
-import pytest
-
from services.workflow.queue_dispatcher import (
- BaseQueueDispatcher,
ProfessionalQueueDispatcher,
QueueDispatcherManager,
QueuePriority,
@@ -35,10 +32,6 @@ class TestDispatchers:
assert d.get_queue_name() == QueuePriority.SANDBOX
assert d.get_priority() == 10
- def test_base_dispatcher_is_abstract(self):
- with pytest.raises(TypeError):
- BaseQueueDispatcher()
-
class TestQueueDispatcherManager:
@patch("services.workflow.queue_dispatcher.BillingService")