Ejemplo n.º 1
0
 def __init__(self, queue: Any, prefetch: int, timeout: int) -> None:
     self.logger = get_logger(__name__, type(self))
     self.queue = queue
     self.prefetch = min(prefetch, MAX_PREFETCH)
     self.timeout = timeout  # UNUSED
     self.messages: deque = deque()
     self.message_refc = 0
Ejemplo n.º 2
0
 def __init__(self, *, backend: EventBackend, abortable: bool = True):
     self.logger = get_logger(__name__, type(self))
     self.abortable = abortable
     self.backend = backend
     self.wait_timeout = 1000
     self.abort_ttl = 90000
     self.abortables: Dict[str, int] = {}
     # This lock avoid race between the monitor and a task cleaning up.
     self.lock = threading.Lock()
Ejemplo n.º 3
0
    def __init__(self, *, namespace="dramatiq-results", encoder=None, client=None, url=None, **parameters):
        super().__init__(namespace=namespace, encoder=encoder)
        self.logger = get_logger(__name__, type(self))

        if url:
            parameters["connection_pool"] = redis.ConnectionPool.from_url(url)

        # TODO: Replace usages of StrictRedis (redis-py 2.x) with Redis in Dramatiq 2.0.
        self.client = client or redis.StrictRedis(**parameters)
Ejemplo n.º 4
0
class Abortable(Middleware):
    """Middleware that interrupts actors whose job has been signaled for
    termination.
    Currently, this is only available on CPython.

    This middleware also adds an ``abortable`` option that can be set on
    dramatiq ``actor`` and ``send_with_options``. Value priority is respectively
    ``send_with_options``, ``actor`` and this ``Abortable``.

    Note: This works by setting an async exception in the worker thread
    that runs the actor.  This means that the exception will only get
    called the next time that thread acquires the GIL. Concretely,
    this means that this middleware can't cancel system calls.

    :param backend: Event backend used to signal termination from a broker to
        the workers. See :class:`RedisBackend`.
    :type backend: :class:`EventBackend`

    :param abortable: Set the default value for every actor ``abortable``
        option.
    """

    def __init__(
        self,
        *,
        backend: EventBackend,
        abortable: bool = True,
        abort_ttl: int = 90_000,
    ):
        self.logger = get_logger(__name__, type(self))
        self.abortable = abortable
        self.backend = backend
        self.wait_timeout = 1000
        self.abort_ttl = abort_ttl
        self.manager: Any = None
        if is_gevent_active():
            self.manager = _GeventAbortManager(self.logger)
        else:
            self.manager = _CtypesAbortManager(self.logger)
        # This lock avoid race between the monitor and a task cleaning up.
        self.lock = threading.Lock()
Ejemplo n.º 5
0
 def __init__(self, logger: Optional[Logger] = None):
     self.logger = logger or get_logger(__name__, type(self))
     self.abortables: Dict[str, Tuple[int, Greenlet]] = {}