o
    wvXj  ã                   @   s¨   d 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mZ ddlmZmZ ddlmZ G d	d
„ d
e	ƒZG dd„ deƒZG dd„ deƒZG dd„ de	ƒZdS )z@The ``celery control``, ``. inspect`` and ``. status`` programs.é    )Úabsolute_importÚunicode_literals)Údumps)Úcached_property)ÚCommand)ÚitemsÚstring_t)ÚEX_UNAVAILABLEÚEX_USAGE)Útextc                       s´   e Zd ZdZdZdZ‡ fdd„Zdd„ Ze		d!d	d
„ƒZ	e		d"dd„ƒZ
dd„ Zdd„ Zdd„ Zdd„ Z	d#dd„Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZedd „ ƒZ‡  ZS )$Ú_RemoteControlNFc                    s6   |  dd¡| _|  dd¡| _tt| ƒj|i |¤Ž d S )NÚ	show_bodyTÚ
show_reply)Úpopr   r   Úsuperr   Ú__init__©ÚselfÚargsÚkwargs©Ú	__class__© úO/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/control.pyr      s   z_RemoteControl.__init__c                 C   sD   |  d¡}|jddtdd� |jdddd	� |jd
ddddd� d S )NzRemote Control Optionsz	--timeoutz-tz,Timeout in seconds (float) waiting for reply)ÚtypeÚhelpz--destinationz-dz/Comma separated list of destination node names.)r   z--jsonz-jÚ
store_trueFzUse json as output format.)ÚactionÚdefaultr   )Úadd_argument_groupÚadd_argumentÚfloat)r   ÚparserÚgroupr   r   r   Úadd_arguments   s   
þþ
þz_RemoteControl.add_argumentsr   Ú c           	   
   C   sh   |d u r	|   |¡}|| }|rdt |j|d ¡ }nd }t dt d |||ƒ|jp,d¡|¡ |g¡S )Nú|é   z
{0}{1} {2}r%   )Ú_choices_by_groupr   Úindentr   ÚjoinÚformatÚ	signature)	ÚclsÚcommandr)   ÚprefixÚcolorr   ÚappÚchoicesÚmetar   r   r   Úget_command_info&   s   

ÿÿýz_RemoteControl.get_command_infoc              	      sR   ˆ  ˆ ¡‰ˆr	ˆndd„ ‰ˆrˆd nd‰d ‡ ‡‡‡‡‡‡fdd„tˆƒD ƒ¡S )Nc                 S   s   | S ©Nr   )Úxr   r   r   Ú<lambda>;   s    z._RemoteControl.list_commands.<locals>.<lambda>ú r%   Ú
c              
   3   s(   � | ]}ˆj |ˆˆˆˆˆ ˆd �V  qdS ))r1   r2   N)r4   )Ú.0Úc©r1   r2   r-   r0   r   r)   r/   r   r   Ú	<genexpr>=   s   € þÿ
ÿz/_RemoteControl.list_commands.<locals>.<genexpr>)r(   r*   Úsorted)r-   r)   r/   r0   r   r1   r   r<   r   Úlist_commands7   s   
ýz_RemoteControl.list_commandsc                 C   s   d  || j¡S )Nz3%(prog)s {0} [options] {1} <command> [arg1 .. argN])r+   r   )r   r.   r   r   r   ÚusageB   s   ÿz_RemoteControl.usagec                 O   s   t dƒ‚)NÚcall)ÚNotImplementedErrorr   r   r   r   rA   F   s   z_RemoteControl.callc                 O   s&   |s
|   d | ¡¡‚| j|fi |¤ŽS )Nz$Missing {0.name} method.  See --help)Ú
UsageErrorr+   Údo_call_methodr   r   r   r   ÚrunI   s
   ÿz_RemoteControl.runc                 C   sR   | j  ¡ �}| d¡s|  d | ¡ d ¡¡‚W d   ƒ d S 1 s"w   Y  d S )NÚfanoutz*Broadcast not supported by transport {0!r}Ú	transport)r1   Úconnection_for_writeÚsupports_exchange_typeÚErrorr+   Úinfo)r   Úconnr   r   r   Ú_ensure_fanout_supportedO   s   

ÿÿÿ"ÿz'_RemoteControl._ensure_fanout_supportedc           	   	   K   sÜ   |d }|dkr|   d | ¡¡‚z| j| }W n ty'   |  d | |¡¡‚w |  ¡  |p0|j}|rBt|tƒrBdd„ | 	d¡D ƒ}| j
||  |||dd … ¡|||rUd n| jd	�}|sc| j d
td�‚|rl|  t|ƒ¡ |S )Nr   r   zDid you mean '{0.name} --help'?zUnknown {0.name} method {1}c                 S   s   g | ]}|  ¡ ‘qS r   )Ústrip)r:   Údestr   r   r   Ú
<listcomp>e   s    z1_RemoteControl.do_call_method.<locals>.<listcomp>ú,é   )Ú	argumentsÚtimeoutÚdestinationÚcallbackz(No nodes replied within time constraint.©Ústatus)rJ   r+   r2   ÚKeyErrorrC   rM   Údefault_timeoutÚ
isinstancer   ÚsplitrA   Úcompile_argumentsÚsay_remote_command_replyr	   Úoutr   )	r   r   rT   rU   Újsonr   Úmethodr3   Úrepliesr   r   r   rD   V   s8   
ÿÿ
ûÿz_RemoteControl.do_call_methodc                 C   sj   t |ƒ}i }|jr| dd„ |  |||¡D ƒ¡ |jr#| |j|i¡ |s1|r1| jd |¡td�‚|p4i S )Nc                 S   s   i | ]\}}||“qS r   r   )r:   ÚkÚvr   r   r   Ú
<dictcomp>y   s    
ÿz4_RemoteControl.compile_arguments.<locals>.<dictcomp>z!Command {0!r} takes no arguments.rW   )Úlistr   ÚupdateÚ_consume_argsÚvariadicrJ   r+   r
   )r   r3   ra   r   Úkwr   r   r   r]   u   s   
ÿþz _RemoteControl.compile_argumentsc              
   c   sÄ   � d}zSt |ƒD ]4\}}z	|j| \}}W n ty.   |jr"Y  n(| jd ||j¡td�‚w ||d ur8||ƒn|fV  qW ||d … |d d …< d S W ||d … |d d …< d S ||d … |d d …< w )Nr   z"Command {0!r} takes arguments: {1}rW   )Ú	enumerater   Ú
IndexErrorri   rJ   r+   r,   r
   )r   r3   ra   r   ÚiÚargÚnameÚtypr   r   r   rh   „   s*   €ÿýýõø.z_RemoteControl._consume_argsc                    s.   ddl m} |j ¡  ‡ fdd„t|jƒD ƒS )Nr   )ÚPanelc                    s(   i | ]\}}|j ˆ jkr|jr||“qS r   )r   Úcontrol_groupÚvisible)r:   ro   rK   ©r-   r   r   re   œ   s
    ÿz4_RemoteControl._choices_by_group.<locals>.<dictcomp>)Úcelery.worker.controlrq   ÚloaderÚimport_default_modulesr   r3   )r-   r1   rq   r   rt   r   r(   –   s
   

ÿz _RemoteControl._choices_by_groupc                 C   s   |   | j¡S r5   )r(   r1   ©r   r   r   r   r2   ¡   s   z_RemoteControl.choicesc                 C   s   d  d| jdd| jd�g¡S )Nr9   z
[Commands]r'   T)r)   r   r1   )r*   r?   r1   rx   r   r   r   Úepilog¥   s   þz_RemoteControl.epilog)r   r%   NFNN)r   r%   NFN)NNF)Ú__name__Ú
__module__Ú__qualname__ro   Úleafrr   r   r$   Úclassmethodr4   r?   r@   rA   rE   rM   rD   r]   rh   r(   r   r2   Úpropertyry   Ú__classcell__r   r   r   r   r      s8    þÿ

ÿ


r   c                   @   ó    e Zd ZdZd Zd Zdd„ ZdS )Úinspecta4  Inspect the worker at runtime.

    Availability: RabbitMQ (AMQP) and Redis transports.

    Examples:
        .. code-block:: console

            $ celery inspect active --timeout=5
            $ celery inspect scheduled -d worker1@example.com
            $ celery inspect revoked -d w1@e.com,w2@e.com
    c                 K   s"   | j jjdi |¤Žj|fi |¤ŽS )Nr   )r1   Úcontrolr‚   Ú_request©r   ra   rS   Úoptionsr   r   r   rA   ½   s
   ÿÿzinspect.callN©rz   r{   r|   Ú__doc__ro   rr   rA   r   r   r   r   r‚   ­   s
    r‚   c                   @   r�   )rƒ   a  Workers remote control.

    Availability: RabbitMQ (AMQP), Redis, and MongoDB transports.

    Examples:
        .. code-block:: console

            $ celery control enable_events --timeout=5
            $ celery control -d worker1@example.com enable_events
            $ celery control -d w1.e.com,w2.e.com enable_events

            $ celery control -d w1.e.com add_consumer queue_name
            $ celery control -d w1.e.com cancel_consumer queue_name

            $ celery control add_consumer queue exchange direct rkey
    c                 K   s   | j jj|f|ddœ|¤ŽS )NT)rS   Úreply)r1   rƒ   Ú	broadcastr…   r   r   r   rA   ×   s   ÿÿÿzcontrol.callNr‡   r   r   r   r   rƒ   Â   s
    rƒ   c                   @   s   e Zd ZdZejZdd„ ZdS )rX   z%Show list of workers that are online.c              	   O   s|   t | j| dd¡| j| jdddd�}|jdi |¤Ž}|s#| jdtd�‚t|ƒ}| dd¡s<|  	d	 
|t |d
¡¡¡ d S d S )NÚno_colorFT)r1   r‹   ÚstdoutÚstderrr   r   ÚquietÚpingz'No nodes replied within time constraintrW   rŽ   z
{0} {1} online.Únode)r�   )r‚   r1   ÚgetrŒ   r�   rE   rJ   r	   Úlenr_   r+   r   Ú	pluralize)r   r   r   ÚIrb   Ú	nodecountr   r   r   rE   á   s"   
üÿ
ÿÿz
status.runN)rz   r{   r|   rˆ   r‚   Úoption_listrE   r   r   r   r   rX   Ü   s    rX   N)rˆ   Ú
__future__r   r   Úkombu.utils.jsonr   Úkombu.utils.objectsr   Úcelery.bin.baser   Úcelery.fiver   r   Úcelery.platformsr	   r
   Úcelery.utilsr   r   r‚   rƒ   rX   r   r   r   r   Ú<module>   s     !