o
    Df!                     @   s*  d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ d4ddZdd Zdd Zed ZdededdfddZdefddZdedefddZeje
dejddee dd d!d"ejd#d$ee	d d%d&ejd'd(ed)d d*d+ej!ed,d- Z"eje
d.d)id/e#ded0ejddee dd d!d"ejd#d$ee	d d%d&ejd'd(ed)d d*d+ej!ed1d0 Z$eje
d.d)id/e#ded2ejddee dd d!d"ejd#d$ee	d d%d&ejd'd(ed)d d*d+ej!ed3d2 Z%dS )5z@The ``celery control``, ``. inspect`` and ``. status`` programs.    )partial)LiteralN)dumps)COMMA_SEPARATED_LISTCeleryCommandCeleryOptionhandle_preload_options)CeleryCommandException)EX_UNAVAILABLE)text)PanelFc                 C   sl   t t|}|| }| jj| dddd}| j|\}}| jjd| | |r/t|dnd|d d S )	Nz: cyanT)fgboldz->    )	show_body)nextiterobjstyleprettysay_chatr   indent)ctxreplies
show_replynodereplystatuspreply r!   K/home/ubuntu/webapp/venv/lib/python3.10/site-packages/celery/bin/control.py_say_remote_command_reply   s   
r#   c              
   c   s    d}zQt |D ]2\}}z	| j| \}}W n ty,   | jr"Y  n&td|| jw ||d ur6||n|fV  qW ||d  |d d < d S W ||d  |d d < d S ||d  |d d < w )Nr   z Command {!r} takes arguments: {})	enumerateargs
IndexErrorvariadicclick
UsageErrorformat	signature)metamethodr%   iargnametypr!   r!   r"   _consume_arguments   s(   .r2   c                 C   sJ   t j|  }i }|jr|dd t|| |D  |jr#||j|i |S )Nc                 S   s   i | ]\}}||qS r!   r!   ).0kvr!   r!   r"   
<dictcomp>/   s    
z&_compile_arguments.<locals>.<dictcomp>)r   r,   r%   updater2   r'   )commandr%   r,   	argumentsr!   r!   r"   _compile_arguments+   s   


r:   )inspectcontroltype_r8   returnc                 C   s<   t | }||vrd|}tjd| d|  d| dd S )Nz, zCommand z not recognized. Available z commands: )message)_get_commands_of_typejoinr(   r)   )r=   r8   choicescommand_listingr!   r!   r"   _verify_command_name:   s   
rD   c                    s6   dt jdd f fdd}t jddd  dd	d|d
S )Nr   r>   c           	         s   |sd S t  }t }|   d. g }| D ]\}}|jr-| d|j }n|}|||jf q|	| W d    n1 sGw   Y  | j
j| dd |   d S )Nz	 Commands F)nl)r@   r(   HelpFormattersection
capitalizeitemsr+   appendhelpwrite_dlr   echogetvalueexit)	r   paramvaluerB   	formattercommand_listcommand_nameinfocommand_previewr=   r!   r"   callbackE   s   	z_list_option.<locals>.callbackz--listTzList available z commands and exit.F)is_flagrL   expose_valueis_eagerrY   )r(   Contextoption)r=   rY   r!   rX   r"   _list_optionD   s   
r_   c                    s$    fddt j D }tt|S )Nc                    s(   g | ]\}}|j  kr|jr||fqS r!   )typevisible)r3   r0   rV   rX   r!   r"   
<listcomp>c   s
    z)_get_commands_of_type.<locals>.<listcomp>)r   r,   rJ   dictsorted)r=   command_name_info_pairsr!   rX   r"   r@   b   s   
r@   )clsz-tz	--timeoutg      ?zRemote Control Optionsz%Timeout in seconds waiting for reply.)rf   r`   default
help_grouprL   z-dz--destinationz/Comma separated list of destination node names.)rf   r`   rh   rL   z-jz--jsonTzUse json as output format.)rf   rZ   rh   rL   c              	   K   s   |rdnt t| }| jjjj|||d }|stdtd|r(| j	t
| t|}|ddsB| j	d|t|d dS dS )	z%Show list of workers that are online.NtimeoutdestinationrY   'No nodes replied within time constraintr?   	exit_codequietF
{} {} online.r   )r   r#   r   appr<   r;   pingr	   r
   rN   r   lengetr*   r   	pluralize)r   rj   rk   jsonkwargsrY   r   	nodecountr!   r!   r"   r   j   s(   

r   allow_extra_args)rf   context_settingsr;   c              	   K   s   t d| |r	dntt| dd}t|| j}| jjjj|||d}|j	|fi |}	|	s2t
dtd|r>| jt|	 dS t|	}
| jjsV| jd|
t|
d	 dS dS )
z~Inspect the workers by sending them the COMMAND inspect command.

    Availability: RabbitMQ (AMQP) and Redis transports.
    r;   NTr   ri   rl   rm   rp   r   )rD   r   r#   r:   r%   r   rq   r<   r;   _requestr	   r
   rN   r   rs   ro   r*   r   ru   )r   r8   rj   rk   rv   rw   rY   r9   r;   r   rx   r!   r!   r"   r;      s0   


r<   c           	      C   sx   t d| |r	dntt| dd}| j}t||}| jjjj||||d|d}|s.t	dt
d|r:| jt| dS dS )zxSend the COMMAND control command to the workers.

    Availability: RabbitMQ (AMQP), Redis, and MongoDB transports.
    r<   NTr{   )rj   rk   rY   r   r9   rl   rm   )rD   r   r#   r%   r:   r   rq   r<   	broadcastr	   r
   rN   r   )	r   r8   rj   rk   rv   rY   r%   r9   r   r!   r!   r"   r<      s(   

)F)&__doc__	functoolsr   typingr   r(   kombu.utils.jsonr   celery.bin.baser   r   r   r   celery.exceptionsr	   celery.platformsr
   celery.utilsr   celery.worker.controlr   r#   r2   r:   _RemoteControlTypestrrD   r_   rc   r@   r8   r^   floatpass_contextr   argumentr;   r<   r!   r!   r!   r"   <module>   s    



