
    xai                         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y)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y)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.
    Nc           
      r   t        |xs | j                        | _        t        |      | _        |i n|| _        || _        |xs
 t               | _        |xs  | j                  j                  j                  | _
        t        | j                  xs | j                  j                         | j                  j                  j                        | _        | | j                  j                  j                   }|	 | j                  j                  j"                  }	|
 | j                  j                  j$                  }
| | j                  j                  j&                  }|
r|rt)        d      t+        dj-                  | j                  | j                  g      | j                  | j
                  | ||
||	      | _        | j                  j0                  | _        | j0                  j2                  | _        | j0                  j6                  | _        |"| j                  j                  j:                  dh}|| _        y )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#   r3   	queue_ttlqueue_expiresqueue_exclusivequeue_durables               h/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/celery/events/receiver.py__init__zEventReceiver.__init__$   s   
 "#/2$W-&.H&($&(LDHHMM,L,L$OO>txx<<>--/ 55I  HHMM==M""hhmmAAO  HHMM==M}&+  HHd''67]](())!%!!	

 XX^^
 JJ--!ZZ//>hhmm44f=F    c                     | j                   j                  |      xs | j                   j                  d      }|xr
  ||       y y)z3Process event by dispatching to configured handler.*N)r   get)r4   typeeventhandlers       r9   processzEventReceiver.processP   s9    --##D)CT]]->->s-C"GEN"r;   c                 \     || j                   g| j                  gd| j                        gS )NT)queues	callbacksno_ackr3   )r,   _receiver3   )r4   Consumerr   s      r9   get_consumerszEventReceiver.get_consumersU   s.    $(MM?4 $- . 	.r;   Tc                 .    |r| j                  |       y y )N)r   )wakeup_workers)r4   r$   r   	consumerswakeupkwargss         r9   on_consume_readyzEventReceiver.on_consume_readyZ   s    0 r;   c                 *    | j                  |||      S )NlimittimeoutrM   consume)r4   rR   rS   rM   s       r9   itercapturezEventReceiver.itercapture_   s    ||%|HHr;   c                 6    | j                  |||      D ]  } y)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`.
        rQ   NrT   )r4   rR   rS   rM   _s        r9   capturezEventReceiver.captureb   s%     E76J 	A	r;   c                 h    | j                   j                  j                  d| j                  |       y )N	heartbeat)r$   r   )r   control	broadcastr$   )r4   r   s     r9   rK   zEventReceiver.wakeup_workersl   s+    "";.2oo+2 	# 	4r;   c                 ^   |d   }|dk(  r4| j                   j                  xs d|z   x}|d<   | j                  |       n	 |d   }	| j                  |	       |r	  ||      \  }
} |||
      |d<    |       |d<   ||fS # t        $ r | j	                         |d<   Y Fw xY w# t        $ r Y ;w xY w)Nr?   z	task-sentr   r-   r   local_received)r-   valuer/   KeyErrorr1   )r4   bodylocalizenowtzfieldsr
   CLIENT_CLOCK_SKEWr?   _cr-   offsetr   s               r9   event_from_messagez EventReceiver.event_from_messageq   s     F|;"&**"2"2"7a;L!LLBgb!)W !!%(H$,TN!	 %5Y$G[!!$Tz  5 $ 2 2 4W5  s$    A> B  >BB 	B,+B,c                      |||      r2| j                   | j                  }}|D cg c]  } | ||        c} y  | j                   | j                  |        y c c}w N)rB   ri   )r4   rb   messagelist
isinstancerB   from_messager@   s           r9   rG   zEventReceiver._receive   sU    dD!$(LL$2I2I\G8<=uWl5)*=DLL$11$78 >s   Ac                 ^    | j                   r | j                   j                  j                  S d S rk   )r   r$   client)r4   s    r9   r$   zEventReceiver.connection   s#    15t||&&--G4Gr;   )
N#NNNNNNNN)T)NNTrk   )__name__
__module____qualname____doc__r   r:   rB   rI   rO   rV   rY   rK   time	_TZGETTERr
   rf   ri   rm   rn   rG   propertyr$    r;   r9   r   r      s     C;>6:<@!%#	*X#
. !%1
I4
 15#yy9,<->6 ,0J 9 H Hr;   r   )rv   rw   operatorr   kombur   kombu.connectionr   kombu.mixinsr   celeryr   
celery.appr   celery.exceptionsr	   celery.utils.timer
   r@   r   __all__rf   rx   r   rz   r;   r9   <module>r      sM    $    * &  % 2 . 
 {K0	~HM ~Hr;   