mirror of
https://github.com/langgenius/dify.git
synced 2026-06-10 18:24:09 +08:00
chore(api): convert BaseQueueDispatcher from ABC to Protocol (#37200)
This commit is contained in:
parent
8a1c0cf5ab
commit
f948e442e0
@ -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):
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user