o
    wvXj7-  ã                   @   s°   d Z ddlmZmZ ddl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 dd
lmZ dZe ZG dd„ deƒZddd„ZedkrVeƒ  dS dS )aç  Program used to start a Celery worker instance.

The :program:`celery worker` command (previously known as ``celeryd``)

.. program:: celery worker

.. seealso::

    See :ref:`preload-options`.

.. cmdoption:: -c, --concurrency

    Number of child processes processing the queue.  The default
    is the number of CPUs available on your system.

.. cmdoption:: -P, --pool

    Pool implementation:

    prefork (default), eventlet, gevent, threads or solo.

.. cmdoption:: -n, --hostname

    Set custom hostname (e.g., 'w1@%%h').  Expands: %%h (hostname),
    %%n (name) and %%d, (domain).

.. cmdoption:: -B, --beat

    Also run the `celery beat` periodic task scheduler.  Please note that
    there must only be one instance of this service.

    .. note::

        ``-B`` is meant to be used for development purposes. For production
        environment, you need to start :program:`celery beat` separately.

.. cmdoption:: -Q, --queues

    List of queues to enable for this worker, separated by comma.
    By default all configured queues are enabled.
    Example: `-Q video,image`

.. cmdoption:: -X, --exclude-queues

    List of queues to disable for this worker, separated by comma.
    By default all configured queues are enabled.
    Example: `-X video,image`.

.. cmdoption:: -I, --include

    Comma separated list of additional modules to import.
    Example: -I foo.tasks,bar.tasks

.. cmdoption:: -s, --schedule

    Path to the schedule database if running with the `-B` option.
    Defaults to `celerybeat-schedule`.  The extension ".db" may be
    appended to the filename.

.. cmdoption:: -O

    Apply optimization profile.  Supported: default, fair

.. cmdoption:: --prefetch-multiplier

    Set custom prefetch multiplier value for this worker instance.

.. cmdoption:: --scheduler

    Scheduler class to use.  Default is
    :class:`celery.beat.PersistentScheduler`

.. cmdoption:: -S, --statedb

    Path to the state database.  The extension '.db' may
    be appended to the filename.  Default: {default}

.. cmdoption:: -E, --task-events

    Send task-related events that can be captured by monitors like
    :program:`celery events`, `celerymon`, and others.

.. cmdoption:: --without-gossip

    Don't subscribe to other workers events.

.. cmdoption:: --without-mingle

    Don't synchronize with other workers at start-up.

.. cmdoption:: --without-heartbeat

    Don't send event heartbeats.

.. cmdoption:: --heartbeat-interval

    Interval in seconds at which to send worker heartbeat

.. cmdoption:: --purge

    Purges all waiting tasks before the daemon is started.
    **WARNING**: This is unrecoverable, and the tasks will be
    deleted from the messaging server.

.. cmdoption:: --time-limit

    Enables a hard time limit (in seconds int/float) for tasks.

.. cmdoption:: --soft-time-limit

    Enables a soft time limit (in seconds int/float) for tasks.

.. cmdoption:: --max-tasks-per-child

    Maximum number of tasks a pool worker can execute before it's
    terminated and replaced by a new worker.

.. cmdoption:: --max-memory-per-child

    Maximum amount of resident memory, in KiB, that may be consumed by a
    child process before it will be replaced by a new one.  If a single
    task causes a child process to exceed this limit, the task will be
    completed and the child process will be replaced afterwards.
    Default: no limit.

.. cmdoption:: --autoscale

    Enable autoscaling by providing
    max_concurrency, min_concurrency. Example::

        --autoscale=10,3

    (always keep 3 processes, but grow to 10 if necessary)

.. cmdoption:: --detach

    Start worker as a background process.

.. cmdoption:: -f, --logfile

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

.. cmdoption:: -l, --loglevel

    Logging level, choose between `DEBUG`, `INFO`, `WARNING`,
    `ERROR`, `CRITICAL`, or `FATAL`.

.. 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 :manpage:`umask(1)` (in octal) of the process after detaching.
    Inherits the :manpage:`umask(1)` of the parent process by default.

.. cmdoption:: --workdir

    Optional directory to change to after detaching.

.. cmdoption:: --executable

    Executable to use for the detached process.
é    )Úabsolute_importÚunicode_literalsN)Úconcurrency)ÚCommandÚdaemon_options)Údetached_celeryd)Ústring_t)Úmaybe_drop_privileges)Ú
LOG_LEVELSÚmlevel)Údefault_nodename)ÚworkerÚmainc                   @   sZ   e Zd ZdZeZd ZdZdZddhZ	ddd„Z
dd	d
„Z		ddd„Zdd„ Zdd„ ZdS )r   aZ  Start worker instance.

    Examples:
        .. code-block:: console

            $ celery worker --app=proj -l info
            $ celery worker -A proj -l info -Q hipri,lopri

            $ celery worker -A proj --concurrency=4
            $ celery worker -A proj --concurrency=1000 -P eventlet
            $ celery worker --autoscale=10,0
    TFz
--no-execvz--force-execvNc                    sx   ‡ fdd„|D ƒ}|d u rt jd n|}|d u rt jdd … n|}ˆ jˆ  |||¡Ž \}}ˆ  |g| ¡ ˆ |i |¤ŽS )Nc                    s   g | ]	}|ˆ j vr|‘qS © )Úremoved_flags)Ú.0Úx©Úselfr   úN/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/worker.pyÚ
<listcomp>Ø   s    z(worker.run_from_argv.<locals>.<listcomp>r   é   )ÚsysÚargvÚprepare_argsÚparse_optionsÚmaybe_detach)r   Ú	prog_namer   ÚcommandÚoptionsÚargsr   r   r   Úrun_from_argv×   s   ÿzworker.run_from_argvc                    sT   ˆsddgnˆ‰t ‡ fdd„ˆD ƒƒr(‡fdd„ˆ D ƒ‰ t| jƒ ˆ ¡ tdƒ‚d S )Nú-Dú--detachc                 3   s   � | ]}|ˆ v V  qd S ©Nr   )r   Úarg)r   r   r   Ú	<genexpr>ã   s   € z&worker.maybe_detach.<locals>.<genexpr>c                    s   g | ]}|ˆ vr|‘qS r   r   )r   Úv)Údoptsr   r   r   ä   s    z'worker.maybe_detach.<locals>.<listcomp>r   )Úanyr   ÚappÚexecute_from_commandlineÚ
SystemExit)r   r   r(   r   )r   r(   r   r   á   s   üzworker.maybe_detachc
                 K   sÎ   t ||d� t |¡p| jjj}| jjr|
 d¡r|  d¡ |  	t
|ƒ¡}|rHzt|ƒ}W n tyG   |  d |d dd„ tD ƒ¡¡¡ Y nw | jjd	|||||  ||¡|  |	|¡dœ|
¤Ž}| ¡  |jS )
N)ÚuidÚgidÚbeatzR-B option does not work on Windows.  Please run celery beat as a separate service.z,Unknown level {0!r}.  Please use one of {1}.ú|c                 s   s   � | ]
}t |tƒr|V  qd S r$   )Ú
isinstancer   )r   Úlr   r   r   r&   ú   s   € 
ÿ
ÿzworker.run.<locals>.<genexpr>)ÚhostnameÚpool_clsÚloglevelÚlogfileÚpidfileÚstatedbr   )r	   r   Úget_implementationr*   ÚconfÚworker_poolÚ
IS_WINDOWSÚgetÚdieÚhost_formatr   r   ÚKeyErrorÚformatÚjoinr
   ÚWorkerÚnode_formatÚstartÚexitcode)r   r3   r4   r*   r-   r.   r5   r6   r7   r8   Úkwargsr   r   r   r   Úruné   s6   
ÿ
ÿ
ÿÿ

üûz
worker.runc                 C   s   dgdgfS )Nú-Pú--poolr   )r   r   r   r   r   Úwith_pool_option  s   zworker.with_pool_optionc           
      C   s  | j j}| d¡}| dd¡ |jddddd� |jd	d
|jd� |jdddd� |jddd� |jdt|jd� | d¡}|jdd|jtd� |jdd|jd� |jdddd|j	d� |jdt
|jd� |jdt
|jd� |jdd t|jd� |jd!d"t|jd� | d#¡}|jd$d%ddd� |jd&d'g d� |jd(d)g d� |jd*d+g d� | d,¡}|jd-ddd� |jd.ddd� |jd/ddd� |jd0td1� | d2¡ t|ƒ | d3¡}|jd4d5ddd� |jd6d7d8|jd� | d9¡ | j jd: }|�r| d;¡}	|  |	|¡ d S d S )<NzWorker Optionsz-nz
--hostnamer"   r#   Ú
store_trueF)ÚactionÚdefaultz-Sz	--statedb)rN   z-lz
--loglevelÚWARNz-OÚoptimization)Údestz--prefetch-multiplier)ÚtyperN   zPool Optionsz-cz--concurrency)rN   rR   rI   rJ   z-Ez--task-eventsz--eventsz--time-limitz--soft-time-limitz--max-tasks-per-childz--maxtasksperchildz--max-memory-per-childz--maxmemperchildzQueue Optionsz--purgez	--discardz--queuesz-Qz--exclude-queuesz-Xz	--includez-IÚFeaturesz--without-gossipz--without-minglez--without-heartbeatz--heartbeat-interval)rR   z--autoscalezEmbedded Beat Optionsz-Bz--beatz-sz--schedule-filenamez
--schedulez--schedulerr   zUser Options)r*   r:   Úadd_argument_groupÚadd_argumentÚworker_state_dbÚintÚworker_prefetch_multiplierÚworker_concurrencyr;   Úworker_send_task_eventsÚfloatÚtask_time_limitÚtask_soft_time_limitÚworker_max_tasks_per_childÚworker_max_memory_per_childr   Úbeat_schedule_filenameÚuser_optionsÚadd_compat_options)
r   Úparserr:   ÚwoptsÚtoptsÚqoptsÚfoptsÚboptsra   Úuoptsr   r   r   Úadd_arguments  sž   
þþþ
þþþþþþþ
þ
ÿÿÿ

þ

þzworker.add_arguments)NNr$   )	NNNNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚHELPÚdocÚ	namespaceÚenable_config_from_cmdlineÚsupports_argsr   r!   r   rH   rK   rj   r   r   r   r   r   Ã   s    



ÿr   c                 C   s<   t dkrtjt  tjd< ddlm} |ƒ  t| d� ¡  dS )zStart worker.Ú__main__r   )Úfreeze_support)r*   N)rk   r   ÚmodulesÚbilliardru   r   r+   )r*   ru   r   r   r   r   c  s
   r   rt   r$   )rn   Ú
__future__r   r   r   Úceleryr   Úcelery.bin.baser   r   Úcelery.bin.celeryd_detachr   Úcelery.fiver   Úcelery.platformsr	   Úcelery.utils.logr
   r   Úcelery.utils.nodenamesr   Ú__all__ro   r   r   rk   r   r   r   r   Ú<module>   s&    1 
!
ÿ