
    leJi                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ dZdZ edd          Z G d de	          ZdS )zEvent receiver implementation.    N)
itemgetter)Queue)maybe_channel)ConsumerMixin)uuid)app_or_default)ImproperlyConfigured)adjust_timestamp   )get_exchange)EventReceiver	utcoffset	timestampc                       e Zd ZdZdZ	 	 	 	 	 ddZd Zd Z	 ddZdd	Z	dd
Z
ddZdej        eeefdZeefdZed             ZdS )r   a?  Capture events.

    Arguments:
        connection (kombu.Connection): Connection to the broker.
        handlers (Mapping[Callable]): Event handlers.
            This is  a map of event type names and their handlers.
            The special handler `"*"` captures all events that don't have a
            handler.
    N#c           
      P   t          |p| j                  | _        t          |          | _        |i n|| _        || _        |pt                      | _        |p| j        j        j	        | _
        t          | j        p| j                                        | j        j        j                  | _        || j        j        j        }|	| j        j        j        }	|
| j        j        j        }
|| j        j        j        }|
r|rt)          d          t+          d                    | j
        | j        g          | j        | j        | ||
||	          | _        | j        j        | _        | j        j        | _        | j        j        | _        || j        j        j        dh}|| _        d S )N)namezDQueue cannot be both exclusive and durable, choose one or the other..)exchangerouting_keyauto_deletedurable	exclusivemessage_ttlexpiresjson)r   appr   channelhandlersr   r   node_idconfevent_queue_prefixqueue_prefixr   
connectionconnection_for_writeevent_exchanger   event_queue_ttlevent_queue_expiresevent_queue_exclusiveevent_queue_durabler	   r   joinqueueclockadjustadjust_clockforwardforward_clockevent_serializeraccept)selfr   r    r   r!   r   r$   r4   	queue_ttlqueue_expiresqueue_exclusivequeue_durables               \/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/celery/events/receiver.py__init__zEventReceiver.__init__$   s   
 "#/22$W--&.H&($&&(LDHM,L$O>tx<<>>-/ / / 5I  HM=M""hmAO  HM=M 	} 	&+   HHd'677]())!%!!	
 	
 	

 X^
 J-!Z/>hm4f=F    c                     | j                             |          p| j                             d          }|o ||           dS  dS )z3Process event by dispatching to configured handler.*N)r    get)r5   typeeventhandlers       r:   processzEventReceiver.processP   sK    -##D))CT]->->s-C-C"GGENNNNN"""r<   c                 D     || j         g| j        gd| j                  gS )NT)queues	callbacksno_ackr4   )r-   _receiver4   )r5   Consumerr   s      r:   get_consumerszEventReceiver.get_consumersU   s4    $(M?4 $- - - . 	.r<   Tc                 :    |r|                      |           d S d S )N)r   )wakeup_workers)r5   r%   r   	consumerswakeupkwargss         r:   on_consume_readyzEventReceiver.on_consume_readyZ   s1     	100000	1 	1r<   c                 2    |                      |||          S )NlimittimeoutrN   consume)r5   rS   rT   rN   s       r:   itercapturezEventReceiver.itercapture_   s    ||%|HHHr<   c                 <    |                      |||          D ]}dS )zOpen up a consumer capturing events.

        This has to run in the main process, and it will never stop
        unless :attr:`EventDispatcher.should_stop` is set to True, or
        forced via :exc:`KeyboardInterrupt` or :exc:`SystemExit`.
        rR   NrU   )r5   rS   rT   rN   _s        r:   capturezEventReceiver.captureb   s2     E76JJ 	 	A	 	r<   c                 T    | j         j                            d| j        |           d S )N	heartbeat)r%   r   )r   control	broadcastr%   )r5   r   s     r:   rL   zEventReceiver.wakeup_workersl   s8    "";.2o+2 	# 	4 	4 	4 	4 	4r<   c                    |d         }|dk    r,| j         j        pd|z   x}|d<   |                     |           nF	 |d         }	|                     |	           n'# t          $ r |                                 |d<   Y nw xY w|r/	  ||          \  }
} |||
          |d<   n# t          $ r Y nw xY w |            |d<   ||fS )Nr@   z	task-sentr   r.   r   local_received)r.   valuer0   KeyErrorr2   )r5   bodylocalizenowtzfieldsr
   CLIENT_CLOCK_SKEWr@   _cr.   offsetr   s               r:   event_from_messagez EventReceiver.event_from_messageq   s(    F|;"&*"2"7a;L!LLBgb!!!!)W !!%((((  5 5 5 $ 2 2 4 4W5
  	HH$,HTNN!	 %5$4Y$G$G[!!     "%Tzs#   A !A>=A>B" "
B/.B/c                      |||          r | j         | j        cfd|D              d S  | j         |                     |            d S )Nc                 ,    g | ]}  |           S  rm   ).0rA   from_messagerC   s     r:   
<listcomp>z*EventReceiver._receive.<locals>.<listcomp>   s*    ===uWWll5))*===r<   )rC   rj   )r5   rc   messagelist
isinstancero   rC   s        @@r:   rH   zEventReceiver._receive   so    :dD!! 	9$(L$2I!G\===========DL$11$778888r<   c                 6    | j         r| j         j        j        nd S N)r   r%   client)r5   s    r:   r%   zEventReceiver.connection   s    15Gt|&--4Gr<   )
Nr   NNNNNNNN)T)NNTru   )__name__
__module____qualname____doc__r   r;   rC   rJ   rP   rW   rZ   rL   time	_TZGETTERr
   rg   rj   rr   rs   rH   propertyr%   rm   r<   r:   r   r      s!         C;>6:<@!%#	* * * *X# # #
. . . !%1 1 1 1
I I I I   4 4 4 4
 15#y9,<->   6 ,0J 9 9 9 9 H H XH H Hr<   r   )rz   r{   operatorr   kombur   kombu.connectionr   kombu.mixinsr   celeryr   
celery.appr   celery.exceptionsr	   celery.utils.timer
   rA   r   __all__rg   r|   r   rm   r<   r:   <module>r      s   $ $              * * * * * * & & & & & &       % % % % % % 2 2 2 2 2 2 . . . . . .      
 J{K00	~H ~H ~H ~H ~HM ~H ~H ~H ~H ~Hr<   