# Path: clearly/utils/data.py
# def accept_task(pattern: Pattern, negate: bool, message: TaskMessage) -> bool:
#     """Find if the message values match the given pattern and negate.
#     This centralizes the search criteria, to both real time streaming
#     and past events.
# 
#     """
#     return _accept(pattern, negate, TASK_OP(message))
# 
# def accept_worker(pattern: Pattern, negate: bool, message: WorkerMessage) -> bool:
#     """Find if the message values match the given pattern and negate.
#     This centralizes the search criteria, to both real time streaming
#     and past events.
# 
#     """
#     return _accept(pattern, negate, WORKER_OP(message))


import logging
import re
import signal
import threading
from contextlib import contextmanager
from enum import Enum
from queue import Empty, Queue
from typing import List, Optional, Pattern, Tuple, Union, Callable
from ..protos.clearly_pb2 import PatternFilter, TaskMessage, WorkerMessage
from ..utils.data import accept_task, accept_worker


logger = logging.getLogger(__name__)

BASE_THREAD_NAME = 'clearly-dispatcher'


class Role(Enum):
    TASKS = (accept_task,)
    WORKERS = (accept_worker,)

    def __new__(cls, func_accept):
        obj = object.__new__(cls)
        obj._value_ = len(cls.__members__) + 1
        obj.__func_accept = func_accept
        return obj

    @property
    def thread_name(self) -> str:
        return '{}-{}'.format(BASE_THREAD_NAME, self.name.lower())


# Path: clearly/utils/data.py
# def accept_task(pattern: Pattern, negate: bool, message: TaskMessage) -> bool:
#     """Find if the message values match the given pattern and negate.
#     This centralizes the search criteria, to both real time streaming
#     and past events.
# 
#     """
#     return _accept(pattern, negate, TASK_OP(message))
# 
# def accept_worker(pattern: Pattern, negate: bool, message: WorkerMessage) -> bool:
#     """Find if the message values match the given pattern and negate.
#     This centralizes the search criteria, to both real time streaming
#     and past events.
# 
#     """
#     return _accept(pattern, negate, WORKER_OP(message))


# Path: clearly/server/streaming_dispatcher.py
import logging
import re
import signal
import threading
from contextlib import contextmanager
from enum import Enum
from queue import Empty, Queue
from typing import List, Optional, Pattern, Tuple, Union, Callable
from ..protos.clearly_pb2 import PatternFilter, TaskMessage, WorkerMessage
from ..utils.data import accept_task, accept_worker



logger = logging.getLogger(__name__)

BASE_THREAD_NAME = 'clearly-dispatcher'


class Role(Enum):
    TASKS = (accept_task,)
    WORKERS = (accept_worker,)

    def __new__(cls, func_accept):
        obj = object.__new__(cls)
        obj._value_ = len(cls.__members__) + 1
        obj.__func_accept = func_accept
        return obj

    @property
    def thread_name(self) -> str:
        return '{}-{}'.format(BASE_THREAD_NAME, self.name.lower())


    @property