From f948e442e003af14bb90924b1027883d2d272dad Mon Sep 17 00:00:00 2001 From: Eric Cao Date: Tue, 9 Jun 2026 10:56:29 +0800 Subject: [PATCH] chore(api): convert BaseQueueDispatcher from ABC to Protocol (#37200) --- api/services/workflow/queue_dispatcher.py | 15 ++++++--------- .../services/workflow/test_queue_dispatcher.py | 7 ------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/api/services/workflow/queue_dispatcher.py b/api/services/workflow/queue_dispatcher.py index 1a79958cc2..0944b20357 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 bbfc1cc294..18b46e40f5 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")