σ
P'^c           @@ 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	 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 d d g Z e  Z d e f d     YZ d d  Z e d k rτ e   n  d S(   u¦  

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, solo or threads.

.. 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:: -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.

.. 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:: -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:: --scheduler

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

.. cmdoption:: -S, --statedb

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

.. cmdoption:: -E, --events

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

.. cmdoption:: --without-gossip

    Do not subscribe to other workers events.

.. cmdoption:: --without-mingle

    Do not synchronize with other workers at startup.

.. cmdoption:: --without-heartbeat

    Do not 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:: --maxtasksperchild

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

.. cmdoption:: --pidfile

    Optional file used to store the workers pid.

    The worker will not start if this file already exists
    and the pid is still alive.

.. 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:: --autoreload

    Enable autoreloading.

.. cmdoption:: --no-execv

    Don't do execv after multiprocessing child fork.

i    (   t   absolute_importt   unicode_literalsN(   t   concurrency(   t   Commandt   Optiont   daemon_options(   t   detached_celeryd(   t   string_t(   t   maybe_drop_privileges(   t   default_nodename(   t
   LOG_LEVELSt   mlevelu   workeru   maint   workerc        
   B@ s}   e  Z d  Z e Z d Z e Z e Z	 d	 d	 d  Z d d g d  Z d	 d	 d	 d	 d	 d	 d	 d	 d	 d 	 Z d   Z d   Z RS(
   u  Start worker instance.

    Examples::

        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
    u   celerydc         C@ s   | d  k r t j d n | } | d  k r8 t j d n | } |  j |  j | | |    \ } } |  j | g |  |  | |   S(   Ni    i   (   t   Nonet   syst   argvt   prepare_argst   parse_optionst   maybe_detach(   t   selft	   prog_nameR   t   commandt   optionst   args(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   run_from_argv¬   s    u   -Du   --detachc         @ sj   t    f d   | D  rf g    D] } | | k r# | ^ q#   t |  j  j    t d   n  d  S(   Nc         3@ s   |  ] } |   k Vq d  S(   N(    (   t   .0t   arg(   R   (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pys	   <genexpr>Ά   s    i    (   t   anyR   t   appt   execute_from_commandlinet
   SystemExit(   R   R   t   doptst   v(    (   R   s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyR   ΅   s    %c
         K@ s  t  d | d |  t j |  p. |  j j j } |  j j r\ |
 j d  r\ |  j d  n  |  j	 t
 |   } | rΚ y t |  } WqΚ t k
 rΖ |  j d j | d j d   t D    qΚ Xn  |  j j d | d	 | d
 | d | d |  j | |  d |  j |	 |  |
  j   S(   Nt   uidt   gidu   beatuR   -B option does not work on Windows.  Please run celery beat as a separate service.u+   Unknown level {0!r}. Please use one of {1}.u   |c         s@ s$   |  ] } t  | t  r | Vq d  S(   N(   t
   isinstanceR   (   R   t   l(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pys	   <genexpr>Ξ   s    t   hostnamet   pool_clst   loglevelt   logfilet   pidfilet   state_db(   R   R   t   get_implementationR   t   conft   CELERYD_POOLt
   IS_WINDOWSt   gett   diet   host_formatR	   R   t   KeyErrort   formatt   joinR
   t   Workert   node_formatt   start(   R   R%   R&   R   R!   R"   R'   R(   R)   R*   t   kwargs(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   runΌ   s$    	c         C@ s   d g d g f S(   Nu   -Pu   --pool(    (   R   R   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   with_pool_optionΧ   s    c         C@ s>  |  j  j } t d d d | j d d t d d d | j d d	 t d
 d d t d d t d d d | j t d d  t d d d d t d d d d d | j t d d d t d d d | j d d t d d d | j	 d d d d t d d d  d d! d | j
 t d" d d# d | j d d  t d$ d d% d | j d d t d& d' d g  t d( d) d g  t d* d+ d g  t d,  t d- d d t d. d d d t t d/ d d d t t d0 d d d t t d1 d d d t t d2 d d t d3 d d4 t d5 d6 d d f t   t |  j  j d7  S(8   Nu   -cu   --concurrencyt   defaultt   typeu   intu   -Pu   --poolt   destu   pool_clsu   --purgeu	   --discardt   actionu
   store_trueu   -lu
   --loglevelu   -nu
   --hostnameu   -Bu   --beatu   -su
   --scheduleu   schedule_filenameu   --scheduleru   scheduler_clsu   -Su	   --statedbu   state_dbu   -Eu   --eventsu   send_eventsu   --time-limitu   floatu   task_time_limitu   --soft-time-limitu   task_soft_time_limitu   --maxtasksperchildu   max_tasks_per_childu   --queuesu   -Qu   --exclude-queuesu   -Xu	   --includeu   -Iu   --autoscaleu   --autoreloadu
   --no-execvu   --without-gossipu   --without-mingleu   --without-heartbeatu   --heartbeat-intervalu   -Ou   optimizationu   -Du   --detachu   worker(   R   R,   R   t   CELERYD_CONCURRENCYR-   t   Falset   CELERYD_LOG_LEVELt   CELERYBEAT_SCHEDULE_FILENAMEt   CELERYD_STATE_DBt   CELERY_SEND_EVENTSt   CELERYD_TASK_TIME_LIMITt   CELERYD_TASK_SOFT_TIME_LIMITt   CELERYD_MAX_TASKS_PER_CHILDR   t   tuplet   user_options(   R   R,   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   get_optionsά   s    "N(   t   __name__t
   __module__t   __doc__t   __MODULE_DOC__t   doct	   namespacet   Truet   enable_config_from_cmdlineR@   t   supports_argsR   R   R   R9   R:   RJ   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyR      s   		c         C@ sQ   t  d k r# t j t  t j d <n  d d l m } |   t d |   j   d  S(   Nu   __main__i    (   t   freeze_supportR   (   RK   R   t   modulest   billiardRT   R   R   (   R   RT   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   main  s
    u   __main__(   RM   t
   __future__R    R   R   t   celeryR   t   celery.bin.baseR   R   R   t   celery.bin.celeryd_detachR   t   celery.fiveR   t   celery.platformsR   t   celery.utilsR	   t   celery.utils.logR
   R   t   __all__RN   R   R   RW   RK   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/worker.pyt   <module>   s   h