Ë
    3ýj(  ã                   óŒ   — d Z ddlZddlZddlZddlmZ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mZmZ d
Z G d„ d«      Zy)zEvent dispatcher sends events.é    N)ÚdefaultdictÚdeque)ÚProducer)Úapp_or_default)Úanon_nodename)Ú	utcoffseté   )ÚEventÚget_exchangeÚ
group_from)ÚEventDispatcherc                   ó´   — e Zd ZdZdhZdZdZdZ	 	 	 	 dd„Zd„ Z	d„ Z
d„ Zd„ Zd	efd
„Zd	efd„Zd	defd„Zd	ed	defd„Zdd„Zd„ Zd„ Zd„ Zd„ Z eee«      Zy)r   a0  Dispatches event messages.

    Arguments:
        connection (kombu.Connection): Connection to the broker.

        hostname (str): Hostname to identify ourselves as,
            by default uses the hostname returned by
            :func:`~celery.utils.anon_nodename`.

        groups (Sequence[str]): List of groups to send events for.
            :meth:`send` will ignore send requests to groups not in this list.
            If this is :const:`None`, all events will be sent.
            Example groups include ``"task"`` and ``"worker"``.

        enabled (bool): Set to :const:`False` to not actually publish any
            events, making :meth:`send` a no-op.

        channel (kombu.Channel): Can be used instead of `connection` to specify
            an exact channel to use when sending events.

        buffer_while_offline (bool): If enabled events will be buffered
            while the connection is down. :meth:`flush` must be called
            as soon as the connection is re-established.

    Note:
        You need to :meth:`close` this after use.
    ÚsqlNc                 óŒ  — t        |xs | j                  «      | _        || _        || _        |xs
 t	        «       | _        || _        |
xs
 t        «       | _        || _	        || _
        t        t        «      | _        t        j                  «       | _        d| _        d | _        t'        «       | _        |xs  | j                  j*                  j,                  | _        t1        «       | _        t1        «       | _        t1        |xs g «      | _        t8        j:                   t8        j<                   g| _        | j                  j@                  | _         |	| _!        |s|r|j                  jD                  | _        || _#        | j                  xs | j                  jI                  «       }tK        || j                  j*                  jL                  ¬«      | _'        |jP                  jR                  | jT                  v rd| _#        | jF                  r| jW                  «        d| j
                  i| _,        t[        j\                  «       | _/        y )NF)ÚnameÚhostname)0r   ÚappÚ
connectionÚchannelr   r   Úbuffer_while_offlineÚ	frozensetÚbuffer_groupÚbuffer_limitÚon_send_bufferedr   ÚlistÚ_group_bufferÚ	threadingÚLockÚmutexÚ_closedÚproducerr   Ú_outbound_bufferÚconfÚevent_serializerÚ
serializerÚsetÚ
on_enabledÚon_disabledÚgroupsÚtimeÚtimezoneÚaltzoneÚtzoffsetÚclockÚdelivery_modeÚclientÚenabledÚconnection_for_writer   Úevent_exchangeÚexchangeÚ	transportÚdriver_typeÚDISABLED_TRANSPORTSÚenableÚheadersÚosÚgetpidÚpid)Úselfr   r   r1   r   r   r   r%   r)   r/   r   r   r   Úconninfos                 úR/root/telegram-saas/.venv/lib/python3.12/site-packages/celery/events/dispatcher.pyÚ__init__zEventDispatcher.__init__:   s¢  € ô " #¢/¨¯©Ó2ˆŒØ$ˆŒØˆŒØ Ò3¤M£OˆŒØ$8ˆÔ!Ø(Ò7¬I«KˆÔØ(ˆÔØ 0ˆÔÜ(¬Ó.ˆÔÜ—^‘^Ó%ˆŒ
ØˆŒØˆŒÜ %£ˆÔØ$ÒF¨¯©¯©×(FÑ(FˆŒÜ›%ˆŒÜ›5ˆÔÜ˜&š, BÓ'ˆŒÜŸ-™-˜¬$¯,©,¨Ð7ˆŒØ—X‘X—^‘^ˆŒ
Ø*ˆÔÙ™gØ%×0Ñ0×7Ñ7ˆDŒOØˆŒØ—?‘?ÒE d§h¡h×&CÑ&CÓ&EˆÜ$ XØ*.¯(©(¯-©-×*FÑ*FôHˆŒà×Ñ×)Ñ)¨T×-EÑ-EÑEØ ˆDŒLØ�<Š<Ø�K‰KŒMØ" D§M¡MÐ2ˆŒÜ—9‘9“;ˆ�ó    c                 ó   — | S ©N© ©r=   s    r?   Ú	__enter__zEventDispatcher.__enter___   s   € ØˆrA   c                 ó$   — | j                  «        y rC   )Úclose)r=   Úexc_infos     r?   Ú__exit__zEventDispatcher.__exit__b   s   € Ø�
‰
�rA   c                 ó  — | j                   5  t        | j                  xs | j                  | j                  | j
                  d¬«      | _        d| _        d| _        d d d «       | j                  D ]	  } |«        Œ y # 1 sw Y   Œ"xY w)NF)r4   r%   Úauto_declareT)
r   r   r   r   r4   r%   r!   r    r1   r'   ©r=   Úcallbacks     r?   r8   zEventDispatcher.enablee   st   € Ø�Z‰Zñ 	 Ü$ T§\¡\Ò%D°T·_±_Ø.2¯m©mØ04·±Ø27ô9ˆDŒMð !ˆDŒLØˆDŒL÷	 ð Ÿ™ò 	ˆHÙ�Jñ	÷	 ð 	 ús   �AA=Á=Bc                 ó|   — | j                   r0d| _         | j                  «        | j                  D ]	  } |«        Œ y y )NF)r1   rH   r(   rM   s     r?   ÚdisablezEventDispatcher.disablep   s8   € Ø�<Š<Ø ˆDŒLØ�J‰JŒLØ ×,Ñ,ò �Ù•
ñð rA   Fc           	      ó¼   — | j                  ||||¬«      }| j                  5   | j                  ||fd|j                  dd«      i|¤Žcddd«       S # 1 sw Y   yxY w)aÄ  Publish event using custom :class:`~kombu.Producer`.

        The supplied producer remains usable after this dispatcher is closed.

        Arguments:
            type (str): Event type name, with group separated by dash (`-`).
                fields: Dictionary of event fields, must be json serializable.
            producer (kombu.Producer): Producer instance to use:
                only the ``publish`` method will be called.
            retry (bool): Retry in the event of connection failure.
            retry_policy (Mapping): Map of custom retry policy options.
                See :meth:`~kombu.Connection.ensure`.
            blind (bool): Don't set logical clock value (also don't forward
                the internal logical clock).
            Event (Callable): Event type used to create event.
                Defaults to :func:`Event`.
            utcoffset (Callable): Function returning the current
                utc offset in hours.
        ©Úblindr
   Úrouting_keyú-ú.N)Ú_prepare_eventr   Ú_publishÚreplace)r=   ÚtypeÚfieldsr!   rS   r
   ÚkwargsÚevents           r?   ÚpublishzEventDispatcher.publishw   sm   € ð* ×#Ñ# D¨&¸ÀUÐ#ÓKˆØ�Z‰Zñ 	OØ �4—=‘= ¨ñ OØ-1¯\©\¸#¸sÓ-CðOØGMñO÷	O÷ 	Oò 	Oús   ¢&AÁAc                 ó’   — |rd n| j                   j                  «       } ||f| j                  t        «       | j                  |dœ|¤ŽS )N©r   r   r<   r.   )r.   Úforwardr   r   r<   )r=   rZ   r[   rS   r
   r.   s         r?   rW   zEventDispatcher._prepare_event‘   sG   € Ù‘ 4§:¡:×#5Ñ#5Ó#7ˆÙ�Tð : D§M¡M¼Y»[ØŸ™¨ñ:Ø28ñ:ð 	:rA   c                 ó  — |€y | j                   }	 |j                  |||j                  |||g| j                  | j                  | j
                  ¬«	       y # t        $ r- | j                  s‚ | j                  j                  ||f«       Y y w xY w)N)rT   r4   ÚretryÚretry_policyÚdeclarer%   r9   r/   )
r4   r^   r   r%   r9   r/   Ú	Exceptionr   r"   Úappend)r=   r]   r!   rT   rc   rd   r   r4   s           r?   rX   zEventDispatcher._publish–   s‘   € àÐØØ—=‘=ˆð	?Ø×ÑØØ'Ø!Ÿ™ØØ)Ø!˜
ØŸ?™?ØŸ™Ø"×0Ñ0ð õ 
øô ò 	?Ø×,Ò,ØØ×!Ñ!×(Ñ(¨%°Ð)=Ö>ð	?ús   ‘AA Á3BÂ
Bc           	      óÀ  — | j                   �rE| j                  t        |«      }	}|r|	|vry|	| j                  v r¨| j                  j                  «       }
 ||f| j                   |«       | j                  |
dœ|¤Ž}| j                  |	   }|j                  |«       t        |«      | j                  k\  r| j                  «        y| j                  r| j                  «        yy| j                  ||||¬«      }| j                  5  | j                   r
	 ddd«       y| j#                  || j$                  |j'                  dd«      ||¬«      cddd«       S y# 1 sw Y   yxY w)aÆ  Send event.

        Arguments:
            type (str): Event type name, with group separated by dash (`-`).
            retry (bool): Retry in the event of connection failure.
            retry_policy (Mapping): Map of custom retry policy options.
                See :meth:`~kombu.Connection.ensure`.
            blind (bool): Don't set logical clock value (also don't forward
                the internal logical clock).
            Event (Callable): Event type used to create event,
                defaults to :func:`Event`.
            utcoffset (Callable): unction returning the current utc offset
                in hours.
            **fields (Any): Event fields -- must be json serializable.
        Nr`   rR   rU   rV   )rT   rc   rd   )r1   r)   r   r   r.   ra   r   r<   r   rg   Úlenr   Úflushr   rW   r   r    rX   r!   rY   )r=   rZ   rS   r   rc   rd   r
   r[   r)   Úgroupr.   r]   Úbufs                r?   ÚsendzEventDispatcher.send¬   sV  € ð" �<‹<Ø ŸK™K¬°DÓ)9�EˆFÙ˜% vÑ-ØØ˜×)Ñ)Ñ)ØŸ
™
×*Ñ*Ó,�Ù˜dð C¨T¯]©]Ù(1«Ø"&§(¡(°%ñCà;AñC�ð ×(Ñ(¨Ñ/�Ø—
‘
˜5Ô!Ü�s“8˜t×0Ñ0Ò0Ø—J‘J•LØ×*Ò*Ø×)Ñ)Õ+ð +ð ×+Ñ+¨D°&ÀØ27ð ,ó 9�à—Z‘Zñ Ø—|’|Ø÷ð ð  Ÿ=™=Ø˜tŸ}™}Ø$(§L¡L°°cÓ$:À%Ø%1ð )ó ÷ñ ð% ÷$ð ús   ÄEÄ/EÅEc                 óV  — |r‚| j                   5  | j                  r
	 ddd«       yt        | j                  «      }| j                  j	                  «        |D ]"  \  }}| j                  || j                  |«       Œ$ 	 ddd«       |r‹| j                   5  | j                  r
	 ddd«       y| j                  j                  «       D ]A  \  }}|sŒ	t        |«      }| j                  || j                  d|z  «       |dt        |«      …= ŒC 	 ddd«       yy# 1 sw Y   Œ—xY w# 1 sw Y   yxY w)zqFlush buffered events.

        Buffers are retained while closed so they can be flushed after enable().
        Nz%s.multi)
r   r    r   r"   ÚclearrX   r!   r   Úitemsri   )	r=   Úerrorsr)   rl   r]   rT   rk   ÚeventsÚbatchs	            r?   rj   zEventDispatcher.flushØ   s(  € ñ
 Ø—‘ñ EØ—<’<Ø÷Eð Eô ˜4×0Ñ0Ó1�Ø×%Ñ%×+Ñ+Ô-Ø*-ò EÑ&�E˜;Ø—M‘M %¨¯©¸ÕDñE÷Eñ Ø—‘ñ ,Ø—<’<Ø÷,ð ,ð &*×%7Ñ%7×%=Ñ%=Ó%?ò ,‘M�E˜6Ù!Ø ô ! ›L�EØ—M‘M %¨¯©¸
ÀUÑ8JÔKØ˜{¤ E£
˜{Ñ+ñ,÷,ð ,ð ÷Eð Eú÷,ð ,ús$   �D¦ADÂDÂ*ADÄDÄD(c                 óN   — | j                   j                  |j                   «       y)z-Copy the outbound buffer of another instance.N)r"   Úextend)r=   Úothers     r?   Úextend_bufferzEventDispatcher.extend_bufferó   s   € à×Ñ×$Ñ$ U×%;Ñ%;Õ<rA   c                 ób   — | j                   5  d| _        d| _        ddd«       y# 1 sw Y   yxY w)zÉClose the dispatcher's own publishing path.

        This can block for as long as an in-flight publish or flush takes.
        Caller-supplied producers remain usable through :meth:`publish`.
        TN)r   r    r!   rE   s    r?   rH   zEventDispatcher.close÷   s.   € ð �Z‰Zñ 	!ØˆDŒLØ ˆDŒM÷	!÷ 	!ñ 	!ús   �%¥.c                 ó   — | j                   S rC   ©r!   rE   s    r?   Ú_get_publisherzEventDispatcher._get_publisher  s   € Ø�}‰}ÐrA   c                 ó   — || _         y rC   rz   )r=   r!   s     r?   Ú_set_publisherzEventDispatcher._set_publisher  s	   € Ø ˆ�rA   )NNTNTNNNr	   Né   N)TT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   r   r'   r(   r@   rF   rJ   r8   rP   r
   r^   rW   r   rX   rm   rj   rw   rH   r{   r}   ÚpropertyÚ	publisherrD   rA   r?   r   r      s¬   „ ñð8 !˜'Ðà
€Cð €Jð €Kà?CØ>BØ=>ØFJó#òJòò	òð  5óOð4 27¸eó :ð
 <AØ"¨ió?ð,  %°	ÀØ eó*óX,ò6=ò!òò!á˜¨Ó8�IrA   r   )r‚   r:   r   r*   Úcollectionsr   r   Úkombur   Ú
celery.appr   Úcelery.utils.nodenamesr   Úcelery.utils.timer   r]   r
   r   r   Ú__all__r   rD   rA   r?   ú<module>r‹      s7   ðÙ $ã 	Û Û ß *å å %Ý 0Ý 'ç 2Ñ 2à
€÷s9ò s9rA   