File: //usr/local/lib/python3.9/site-packages/kombu/__pycache__/mixins.cpython-39.pyc
a
X>h�% � @ s� d Z ddlmZ ddlZddlmZ ddlmZ ddlm Z ddl
mZ dd lm
Z
dd
lmZ ddlmZmZ ddlmZ dd
lmZ ddlmZ ddlmZ dZee�Zejejej ej!f\ZZZ"Z!dZ#dZ$G dd� d�Z%G dd� de%�Z&dS )zMixins.� )�annotationsN)�contextmanager)�partial)�count)�sleep� ��
ignore_errors)�
get_logger)�Consumer�Producer��nested)� safe_repr��TokenBucket)�cached_property)�
ConsumerMixin�ConsumerProducerMixinz?Connection to broker lost, trying to re-establish connection...z8Broker connection error, trying again in %s seconds: %r.c @ s� e Zd ZdZdZdZdd� Zdd� Zdd � Zd
d� Z dd
� Z
dd� Zdd� Ze
dd� �Zd+dd�Ze
dd� �Zd,dd�Zdd� Zdd� Ze
dd � �Ze
d!d"� �Zd#d$� Zed%d&� �Zed'd(� �Zed)d*� �ZdS )-r a' Convenience mixin for implementing consumer programs.
It can be used outside of threads, with threads, or greenthreads
(eventlet/gevent) too.
The basic class would need a :attr:`connection` attribute
which must be a :class:`~kombu.Connection` instance,
and define a :meth:`get_consumers` method that returns a list
of :class:`kombu.Consumer` instances to use.
Supporting multiple consumers is important so that multiple
channels can be used for different QoS requirements.
Example:
-------
.. code-block:: python
class Worker(ConsumerMixin):
task_queue = Queue('tasks', Exchange('tasks'), 'tasks')
def __init__(self, connection):
self.connection = None
def get_consumers(self, Consumer, channel):
return [Consumer(queues=[self.task_queue],
callbacks=[self.on_task])]
def on_task(self, body, message):
print('Got task: {0!r}'.format(body))
message.ack()
Methods
-------
* :meth:`extra_context`
Optional extra context manager that will be entered
after the connection and consumers have been set up.
Takes arguments ``(connection, channel)``.
* :meth:`on_connection_error`
Handler called if the connection is lost/ or
is unavailable.
Takes arguments ``(exc, interval)``, where interval
is the time in seconds when the connection will be retried.
The default handler will log the exception.
* :meth:`on_connection_revived`
Handler called as soon as the connection is re-established
after connection failure.
Takes no arguments.
* :meth:`on_consume_ready`
Handler called when the consumer is ready to accept
messages.
Takes arguments ``(connection, channel, consumers)``.
Also keyword arguments to ``consume`` are forwarded
to this handler.
* :meth:`on_consume_end`
Handler called after the consumers are canceled.
Takes arguments ``(connection, channel)``.
* :meth:`on_iteration`
Handler called for every iteration while draining
events.
Takes no arguments.
* :meth:`on_decode_error`
Handler called if a consumer was unable to decode
the body of a message.
Takes arguments ``(message, exc)`` where message is the
original message object.
The default handler will log the error and
acknowledge the message, so if you override make
sure to call super, or perform these steps yourself.
NFc C s t d��d S )NzSubclass responsibility)�NotImplementedError)�selfr �channel� r �6/usr/local/lib/python3.9/site-packages/kombu/mixins.py�
get_consumers� s zConsumerMixin.get_consumersc C s d S �Nr �r r r r �on_connection_revived� s z#ConsumerMixin.on_connection_revivedc K s d S r r )r �
connectionr � consumers�kwargsr r r �on_consume_ready� s zConsumerMixin.on_consume_readyc C s d S r r �r r r r r r �on_consume_end� s zConsumerMixin.on_consume_endc C s d S r r r r r r �on_iteration� s zConsumerMixin.on_iterationc C s&