o
    wvXj·8  ã                   @   sÈ  d Z ddlmZmZmZ ddlZddlZddlmZ ddl	m
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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dl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1 dZ2dZ3dg d¢dfdg d¢dfdg d ¢dfd!d"d#gd$fgZ4d%d&„ Z5d1d'd(„Z6G d)d*„ d*eƒZ7G d+d,„ d,eƒZ8G d-d"„ d"eƒZ9G d.d/„ d/eƒZ:e;d0krâe6ƒ  dS dS )2aÓ  The :program:`celery` umbrella command.

.. program:: celery

.. _preload-options:

Preload Options
---------------

These options are supported by all commands,
and usually parsed before command-specific arguments.

.. cmdoption:: -A, --app

    app instance to use (e.g., ``module.attr_name``)

.. cmdoption:: -b, --broker

    URL to broker.  default is ``amqp://guest@localhost//``

.. cmdoption:: --loader

    name of custom loader class to use.

.. cmdoption:: --config

    Name of the configuration module

.. cmdoption:: -C, --no-color

    Disable colors in output.

.. cmdoption:: -q, --quiet

    Give less verbose output (behavior depends on the sub command).

.. cmdoption:: --help

    Show help and exit.

.. _daemon-options:

Daemon Options
--------------

These options are supported by commands that can detach
into the background (daemon).  They will be present
in any command that also has a `--detach` option.

.. cmdoption:: -f, --logfile

    Path to log file.  If no logfile is specified, `stderr` is used.

.. cmdoption:: --pidfile

    Optional file used to store the process pid.

    The program won't start if this file already exists
    and the pid is still alive.

.. cmdoption:: --uid

    User id, or user name of the user to run as after detaching.

.. cmdoption:: --gid

    Group id, or group name of the main group to change to after
    detaching.

.. cmdoption:: --umask

    Effective umask (in octal) of the process after detaching.  Inherits
    the umask of the parent process by default.

.. cmdoption:: --workdir

    Optional directory to change to after detaching.

.. cmdoption:: --executable

    Executable to use for the detached process.

``celery inspect``
------------------

.. program:: celery inspect

.. cmdoption:: -t, --timeout

    Timeout in seconds (float) waiting for reply

.. cmdoption:: -d, --destination

    Comma separated list of destination node names.

.. cmdoption:: -j, --json

    Use json as output format.

``celery control``
------------------

.. program:: celery control

.. cmdoption:: -t, --timeout

    Timeout in seconds (float) waiting for reply

.. cmdoption:: -d, --destination

    Comma separated list of destination node names.

.. cmdoption:: -j, --json

    Use json as output format.

``celery migrate``
------------------

.. program:: celery migrate

.. cmdoption:: -n, --limit

    Number of tasks to consume (int).

.. cmdoption:: -t, -timeout

    Timeout in seconds (float) waiting for tasks.

.. cmdoption:: -a, --ack-messages

    Ack messages from source broker.

.. cmdoption:: -T, --tasks

    List of task names to filter on.

.. cmdoption:: -Q, --queues

    List of queues to migrate.

.. cmdoption:: -F, --forever

    Continually migrate tasks until killed.

``celery upgrade``
------------------

.. program:: celery upgrade

.. cmdoption:: --django

    Upgrade a Django project.

.. cmdoption:: --compat

    Maintain backwards compatibility.

.. cmdoption:: --no-backup

    Don't backup original files.

``celery shell``
----------------

.. program:: celery shell

.. cmdoption:: -I, --ipython

    Force :pypi:`iPython` implementation.

.. cmdoption:: -B, --bpython

    Force :pypi:`bpython` implementation.

.. cmdoption:: -P, --python

    Force default Python shell.

.. cmdoption:: -T, --without-tasks

    Don't add tasks to locals.

.. cmdoption:: --eventlet

    Use :pypi:`eventlet` monkey patches.

.. cmdoption:: --gevent

    Use :pypi:`gevent` monkey patches.

``celery result``
-----------------

.. program:: celery result

.. cmdoption:: -t, --task

    Name of task (if custom backend).

.. cmdoption:: --traceback

    Show traceback if any.

``celery purge``
----------------

.. program:: celery purge

.. cmdoption:: -f, --force

    Don't prompt for verification before deleting messages (DANGEROUS)

``celery call``
---------------

.. program:: celery call

.. cmdoption:: -a, --args

    Positional arguments (json format).

.. cmdoption:: -k, --kwargs

    Keyword arguments (json format).

.. cmdoption:: --eta

    Scheduled time in ISO-8601 format.

.. cmdoption:: --countdown

    ETA in seconds from now (float/int).

.. cmdoption:: --expires

    Expiry time in float/int seconds, or a ISO-8601 date.

.. cmdoption:: --serializer

    Specify serializer to use (default is json).

.. cmdoption:: --queue

    Destination queue.

.. cmdoption:: --exchange

    Destination exchange (defaults to the queue exchange).

.. cmdoption:: --routing-key

    Destination routing key (defaults to the queue routing key).
é    )Úabsolute_importÚprint_functionÚunicode_literalsN)Úpartial)Úamqp)ÚCommandÚ
Extensions)Úbeat)Úcall)Ú_RemoteControl)ÚcontrolÚinspectÚstatus)Úevents)Úgraph)Úlist_)Úlogtool)Úmigrate)Úpurge)Úresult)Úshell)Úupgrade)Úworker)Ú
EX_FAILUREÚEX_OKÚEX_USAGE)ÚtermÚtext)ÚCeleryCommandÚmainzË
---- -- - - ---- Commands- -------------- --- ------------

{commands}
---- -- - - --------- -- - -------------- --- ------------

Type '{prog_name} <command> --help' for help using a specific command.
ÚMain)r   r   r	   r   Úmultir   ÚgreenzRemote Control)r   r   r   ÚblueÚUtils)r   Úlistr
   r   r   r   r   Ú	DebuggingÚreportr   Úredc                 C   s   t | tjƒr| S | rtS tS ©N)Ú
isinstanceÚnumbersÚIntegralr   r   )Úret© r.   úN/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/celery.pyÚdetermine_exit_status0  s   r0   c                 C   s^   z$t dkrtjt  tjd< tƒ }| ¡  ddlm} |ƒ  | | ¡ W dS  ty.   Y dS w )zStart celery umbrella command.Ú__main__r   )Úfreeze_supportN)	Ú__name__ÚsysÚmodulesr   Úmaybe_patch_concurrencyÚbilliardr2   Úexecute_from_commandlineÚKeyboardInterrupt)ÚargvÚcmdr2   r.   r.   r/   r   6  s   ÿr   c                   @   s   e Zd ZdZdZddd„ZdS )r!   z Start multiple worker instances.FNc                 C   s,   ddl m} || j| jd�}| |g| ¡S )Nr   )Ú	MultiTool)ÚquietÚno_color)Úcelery.bin.multir<   r=   r>   r8   )ÚselfÚ	prog_namer:   Úcommandr<   r;   r.   r.   r/   Úrun_from_argvL  s   zmulti.run_from_argvr)   )r3   Ú
__module__Ú__qualname__Ú__doc__Úrespects_app_optionrC   r.   r.   r.   r/   r!   G  s    r!   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚhelpzShow help screen and exit.c                 C   s
   d  | ¡S )Nz%%(prog)s <command> [options] {0.args})Úformat©r@   rB   r.   r.   r/   ÚusageU  s   
z
help.usagec                 O   s2   | j  ¡  |  tj| jtj| j| j	d�d�¡ t
S )N)ÚcoloredÚapp)rA   Úcommands)ÚparserÚ
print_helpÚoutÚHELPrI   rA   r   Úlist_commandsrL   rM   r   ©r@   ÚargsÚkwargsr.   r.   r/   ÚrunX  s   
ÿþzhelp.runN)r3   rD   rE   rF   rK   rW   r.   r.   r.   r/   rH   R  s    rH   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r'   z3Shows information useful to include in bug-reports.c                    s&   t t| ƒj|i |¤Ž | jj ¡  dS )a5  Custom initialization for report command.

        We need this custom initialization to make sure that
        everything is loaded when running a report.
        There has been some issues when printing Django's
        settings because Django is not properly setup when
        running the report.
        N)Úsuperr'   Ú__init__rM   ÚloaderÚimport_default_modulesrT   ©Ú	__class__r.   r/   rY   f  s   	zreport.__init__c                 O   s   |   | j ¡ ¡ tS r)   )rQ   rM   Ú	bugreportr   rT   r.   r.   r/   rW   r  s   z
report.run)r3   rD   rE   rF   rY   rW   Ú__classcell__r.   r.   r\   r/   r'   c  s    c                       s  e Zd ZdZi de“de“de“de“de“de	“de
“d	e“d
e“de“de“de“de“de“de“de“de“eedœ¥ZdZdZdZdZed1dd„ƒZd1dd„Zd1dd„Zd2dd „Z d!d"„ Z!d#d$„ Z"d1‡ fd%d&„	Z#e		d3d'd(„ƒZ$ed4d)d*„ƒZ%d+d,„ Z&d-d.„ Z'd/d0„ Z(‡  Z)S )5r   zBase class for commands.r   r	   r
   r   r   r   rH   r   r%   r   r   r!   r   r'   r   r   r   )r   r   z{self.namespace}.commandsTÚceleryNc                 C   s   || j |p|j< |S r)   )rN   r3   )ÚclsÚfunÚnamer.   r.   r/   Úregister_command”  s   zCeleryCommand.register_commandc              
   C   sà   z| j | }W n ty   | j d dg}}Y nw z || j| j| j| jt| j|d�d�j| j	|dd … |d d�W S  | j
yU } z|  |¡ |jW  Y d }~S d }~w | jyo } z|  |¡ |jW  Y d }~S d }~ww )NrH   )rB   )rM   Úon_errorr>   r=   Úon_usage_erroré   r   )rN   ÚKeyErrorrM   re   r>   r=   r   rf   rC   rA   Ú
UsageErrorr   ÚError)r@   rB   r:   ra   Úexcr.   r.   r/   Úexecute™  s,   ÿýü
€
€þzCeleryCommand.executec                 C   sD   |rd}nd}|   | j d |¡¡¡ |   d |j| |d�¡¡ d S )Nz!{self.prog_name} {command} --helpz{self.prog_name} --helpz
Error: {0}zPlease try '{0}'rJ   )ÚerrorrL   ÚmagentarI   )r@   rk   rB   Úhelpsr.   r.   r/   rf   «  s   ÿzCeleryCommand.on_usage_errorr   c                 C   sÚ   |rkg }|t |ƒk rV|| }| d¡r| |¡ n3| d¡rKz||d  }| d¡r0| |¡ n| ||g¡ |d7 }W n tyJ   | |¡ Y nw n
|d7 }|t |ƒk s
||d … rd||d … | S | ¡ g|  g S )Nz--ú-rg   )ÚlenÚ
startswithÚappendÚextendÚ
IndexErrorÚpop)r@   r:   ÚindexÚrestÚvalueÚnxtr.   r.   r/   Ú_relocate_args_from_startµ  s2   


€
þéz'CeleryCommand._relocate_args_from_startc                 C   s   |dkr
t jd jS |S )Nz__main__.pyr1   )r4   r5   Ú__file__)r@   rc   r.   r.   r/   Úprepare_prog_nameÚ  s   zCeleryCommand.prepare_prog_namec                 K   s^   |   |¡| _|  |¡}|  d |¡\}}z|d }W n ty(   ddg}}Y nw |  ||¡S )Nr   rH   )r}   rA   r{   Úprepare_argsru   rl   )r@   rA   r:   rV   Ú_rB   r.   r.   r/   Úhandle_argvß  s   
ÿzCeleryCommand.handle_argvc                    sh   |d u rt jn|}d|dd… v rd| _zt  ttt| ƒ |¡ƒ¡ W d S  ty3   t  t	¡ Y d S w )Nr!   rg   é   F)
r4   r:   rG   Úexitr0   rX   r   r8   r9   r   ©r@   r:   r\   r.   r/   r8   é  s   ÿÿz&CeleryCommand.execute_from_commandlinec              
   C   sŽ   |d u rt  ¡ n|}|r|j| ndd„ }| j| }d ||ƒ¡}|jr,dt ||¡ S t ddt d |¡|¡ |j	|d |¡||d�g¡S )Nc                 S   s   | S r)   r.   )Úxr.   r.   r/   Ú<lambda>÷  s    z0CeleryCommand.get_command_info.<locals>.<lambda>z
celery {0}ú|ú z
{0} --help©rM   )
r   rL   ÚnamesrN   rI   Úleafr   ÚindentÚjoinrS   )ra   rB   r‹   ÚcolorrL   rM   Úobjr;   r.   r.   r/   Úget_command_infoó  s   
ÿýzCeleryCommand.get_command_infoc                    sz   ˆd u rt  ¡ nˆ‰ˆj}g }tD ]$\}}‰| t d ||ƒ¡ˆ¡d ‡ ‡‡‡‡fdd„|D ƒ¡dg¡ qd |¡ 	¡ S )Nz+ {0}: Ú
c                 3   s(   � | ]}ˆj |ˆd  ˆˆˆ d�V  qdS )é   rˆ   N)r�   )Ú.0rB   ©rM   ra   r�   rL   r‹   r.   r/   Ú	<genexpr>  s   € þÿ
ÿz.CeleryCommand.list_commands.<locals>.<genexpr>Ú )
r   rL   ÚwhiteÚcommand_classesrt   r   r‹   rI   rŒ   Ústrip)ra   r‹   rL   rM   r–   r-   Úcommand_clsrN   r.   r“   r/   rS     s   ýúzCeleryCommand.list_commandsc                 C   s0   t |ƒdkrd|dd… v rdgdgfS d S d S )Nrg   r   r   r�   z-Pz--pool)rq   rƒ   r.   r.   r/   Úwith_pool_option  s   ýzCeleryCommand.with_pool_optionc                 C   s   |   ¡  d S r)   )Úload_extension_commands©r@   r.   r.   r/   Úon_concurrency_setup  s   z"CeleryCommand.on_concurrency_setupc                 C   s6   t | jj| d�| jƒ ¡ }|rt d|df¡ d S d S )Nrœ   r   rn   )r   Úext_fmtrI   rd   Úloadr—   rs   )r@   r‰   r.   r.   r/   r›     s   ÿÿÿz%CeleryCommand.load_extension_commandsr)   )r   )r   NNN)r   NN)*r3   rD   rE   rF   r   r	   r
   r   r   r   rH   r   r   r   r   r!   r   r'   r   r   r   r   r   rN   rž   Úenable_config_from_cmdlinerA   Ú	namespaceÚclassmethodrd   rl   rf   r{   r}   r€   r8   r�   rS   rš   r�   r›   r_   r.   r.   r\   r/   r   w  sz    ÿþýüûúùø	÷
öõôóòñðïí



%

ÿr   r1   r)   )<rF   Ú
__future__r   r   r   r+   r4   Ú	functoolsr   Úcelery.bin.amqpr   Úcelery.bin.baser   r   Úcelery.bin.beatr	   Úcelery.bin.callr
   Úcelery.bin.controlr   r   r   r   Úcelery.bin.eventsr   Úcelery.bin.graphr   Úcelery.bin.listr   Úcelery.bin.logtoolr   Úcelery.bin.migrater   Úcelery.bin.purger   Úcelery.bin.resultr   Úcelery.bin.shellr   Úcelery.bin.upgrader   Úcelery.bin.workerr   Úcelery.platformsr   r   r   Úcelery.utilsr   r   Ú__all__rR   r—   r0   r   r!   rH   r'   r   r3   r.   r.   r.   r/   Ú<module>   sX    
þú

 -
ÿ