HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/kombu/__pycache__/mixins.cpython-39.pyc
a

X>h�%�@s�dZddlmZddlZddlmZddlmZddlm	Z	ddl
mZdd	lm
Z
dd
lmZddlmZmZddlmZdd
lmZddlmZddlmZdZee�Zejejej ej!f\ZZZ"Z!dZ#dZ$Gdd�d�Z%Gdd�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�eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Ze
dd��Zd+dd�Ze
dd��Zd,dd�Zdd�Zdd�Ze
dd ��Ze
d!d"��Zd#d$�Zed%d&��Zed'd(��Zed)d*��ZdS)-ra'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.

    NFcCstd��dS)NzSubclass responsibility)�NotImplementedError)�selfr�channel�r�6/usr/local/lib/python3.9/site-packages/kombu/mixins.py�
get_consumers�szConsumerMixin.get_consumerscCsdS�Nr�rrrr�on_connection_revived�sz#ConsumerMixin.on_connection_revivedcKsdSrr)r�
connectionr�	consumers�kwargsrrr�on_consume_ready�szConsumerMixin.on_consume_readycCsdSrr�rrrrrr�on_consume_end�szConsumerMixin.on_consume_endcCsdSrrrrrr�on_iteration�szConsumerMixin.on_iterationcCs&td||j|jt|j��|��dS)Nz;Can't decode message body: %r (type:%r encoding:%r raw:%r'))�error�content_type�content_encodingr�bodyZack)r�message�excrrr�on_decode_error�s

�zConsumerMixin.on_decode_errorcCstt||dd�dS)Nr��exc_info)�warn�W_CONN_ERROR)rr*�intervalrrr�on_connection_error�sz!ConsumerMixin.on_connection_errorccs
dVdSrrr"rrr�
extra_context�szConsumerMixin.extra_contextrcKsz|j}|jj|jj}|jsvz8|�|�rD|jfddi|��D]}q<nt|�|��Wq|yrt	t
dd�Yq0qdS)N�limitrr,)�
restart_limitr�connection_errors�channel_errors�should_stopZcan_consume�consumerZ
expected_timer.�W_CONN_LOST)rZ_tokensr r4�errors�_rrr�run�s�
zConsumerMixin.runc	ks�|���d\}}}|�||��2|j|||fi|��|||fVWd�n1sT0YWd�n1sr0YdSr)rr2r!)rr rrrrrr�consumer_context�szConsumerMixin.consumer_contextc

ks�d}|jfi|����\}}}|r(t|�p,t�D]|}	|jr<q�|��z|j|d�WnJtjy�|��||7}|r�||kr��Yq.t	y�|js��Yq.0dVd}q.Wd�n1s�0Yt
d�dS)Nr)�timeoutzconsume exiting)r=�rangerr7r$Zdrain_events�socketr>Zheartbeat_check�OSError�debug)
rr3r>Zsafety_intervalr �elapsed�connrr�irrrr8�s&$zConsumerMixin.consumecCs
t||�S)z/Use :func:`kombu.common.ignore_errors` instead.r)rZfunrrr�maybe_conn_error�szConsumerMixin.maybe_conn_errorcCs
|j��Sr)r�clonerrrr�create_connection�szConsumerMixin.create_connectionccsB|���&}|�|j|j�|VWd�n1s40YdSr)rH�ensure_connectionr1�connect_max_retries�rrDrrr�establish_connection�s

�z"ConsumerMixin.establish_connectionc	cs�|����}|��td|���|j}tt||jd�}|j|�	||���}|||fVWd�n1sj0Yt
d�|�||�Wd�n1s�0Yt
d�dS)NzConnected to %s)r+zConsumers canceledzConnection closed)rLr�info�as_uriZdefault_channelrrr+�
_consume_fromrrBr#)rrDr�cls�crrrr�s
�**zConsumerMixin.ConsumercGst|�Srr
)rrrrrrO�szConsumerMixin._consume_fromcCstd�S)Nrrrrrrr4�szConsumerMixin.restart_limitcCs|jjSr)rr5rrrrr5�szConsumerMixin.connection_errorscCs|jjSr)rr6rrrrr6�szConsumerMixin.channel_errors)r)NNr)�__name__�
__module__�__qualname__�__doc__rJr7rrr!r#r$r+r1rr2r<r=r8rFrHrLrrOrr4r5r6rrrrr&s:]








rc@s4eZdZdZdZdd�Zedd��Zedd��ZdS)	raConsumer and Producer mixin.

    Version of ConsumerMixin having separate connection for also
    publishing messages.

    Example:
    -------
        .. code-block:: python

            class Worker(ConsumerProducerMixin):

                def __init__(self, connection):
                    self.connection = connection

                def get_consumers(self, Consumer, channel):
                    return [Consumer(queues=Queue('foo'),
                                     on_message=self.handle_message,
                                     accept='application/json',
                                     prefetch_count=10)]

                def handle_message(self, message):
                    self.producer.publish(
                        {'message': 'hello to you'},
                        exchange='',
                        routing_key=message.properties['reply_to'],
                        correlation_id=message.properties['correlation_id'],
                        retry=True,
                    )
    NcCs|jdur|j��d|_dSr)�_producer_connection�closer"rrrr#s

z$ConsumerProducerMixin.on_consume_endcCs
t|j�Sr)r�producer_connectionrrrr�producer$szConsumerProducerMixin.producercCs0|jdur*|j��}|�|j|j�||_|jSr)rVrrGrIr1rJrKrrrrX(s

�z)ConsumerProducerMixin.producer_connection)	rRrSrTrUrVr#�propertyrYrXrrrrr�s
r)'rU�
__future__rr@�
contextlibr�	functoolsr�	itertoolsr�timer�commonr	�logr
Z	messagingrrZutils.compatrZutils.encodingrZutils.limitsrZ
utils.objectsr�__all__rR�loggerrBrM�warningr%r.r9r/rrrrrr�<module>s2�Y