σ
P'^c           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l m Z m Z 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 d d
 l m Z d d l m Z d d d d d d d g Z d Z d Z d e j f d     YZ d e j f d     YZ d e j f d     YZ  d e j f d     YZ! d e j f d     YZ" d e j f d     YZ# d e j f d     YZ$ d S(   s[   
    celery.worker.components
    ~~~~~~~~~~~~~~~~~~~~~~~~

    Default worker bootsteps.

i    (   t   absolute_importN(   t   Hubt   get_event_loopt   set_event_loop(   t	   DummyLockt   LaxBoundedSemaphore(   t   Timer(   t	   bootsteps(   t   _set_task_join_will_block(   t   ImproperlyConfigured(   t   string_t(   t   worker_loggerR   R   t   Queuest   Poolt   Beatt   StateDBt   ConsumersO   -B option doesn't work with eventlet/gevent pools: use standalone beat instead.s«   
The CELERYD_POOL setting should not be used to select the eventlet/gevent
pools, instead you *must use the -P* argument so that patches are applied
as early as possible.
c           B@  s)   e  Z d  Z d   Z d   Z d   Z RS(   s<   This step initializes the internal timer used by the worker.c         C@  sm   | j  r t d d  | _ nK | j s9 | j j | _ n  |  j | j d | j d |  j d |  j	 | _ d  S(   Nt   max_intervalg      $@t   on_timer_errort   on_timer_tick(
   t   use_eventloopt   _Timert   timert	   timer_clst   pool_clsR   t   instantiatet   timer_precisionR   R   (   t   selft   w(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt   create)   s    				c         C@  s   t  j d | d t d  S(   Ns   Timer error: %rt   exc_info(   t   loggert   errort   True(   R   t   exc(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   7   s    c         C@  s   t  j d |  d  S(   Ns    Timer wake-up! Next eta %s secs.(   R   t   debug(   R   t   delay(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   :   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   &   s   		c           B@  sP   e  Z e f Z d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         K@  s   d  | _ d  S(   N(   t   Nonet   hub(   R   R   t   kwargs(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt   __init__A   s    c         C@  s   | j  S(   N(   R   (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt
   include_ifD   s    c         C@  sG   t    | _ | j d  k r6 t t | j   | _ n  |  j |  |  S(   N(   R   R)   R(   R   t   _HubR   t   _patch_thread_primitives(   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   G   s
    c         C@  s   d  S(   N(    (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt   startN   s    c         C@  s   | j  j   d  S(   N(   R)   t   close(   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt   stopQ   s    c         C@  s   | j  j   d  S(   N(   R)   R0   (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt	   terminateT   s    c         C@  sG   t    | j j _ y d d l m } Wn t k
 r9 n
 Xt  | _ d  S(   Ni    (   t   pool(   R   t   appt   clockt   mutext   billiardR3   t   ImportErrort   Lock(   R   R   R3   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR.   W   s    (   R%   R&   R   t   requiresR+   R,   R   R/   R1   R2   R.   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   >   s   							c           B@  s&   e  Z d  Z d Z e f Z d   Z RS(   sE   This bootstep initializes the internal queues
    used by the worker.s   Queues (intra)c         C@  s@   | j  | _ | j r< | j r< | j j r< | j | _ q< n  d  S(   N(   t   _process_taskt   process_taskR   t   pool_putlocksR   t   uses_semaphoret   _process_task_sem(   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   i   s    	(   R%   R&   R'   t   labelR   R:   R   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   c   s   	c           B@  s_   e  Z d  Z e f Z d d e d d  Z d   Z d   Z	 d d d  Z
 d   Z d   Z RS(   s
  Bootstep managing the worker pool.

    Describes how to initialize the worker pool, and starts and stops
    the pool during worker startup/shutdown.

    Adds attributes:

        * autoscale
        * pool
        * max_concurrency
        * min_concurrency

    c   
      K@  s΅   t  | t  rN | j d  \ } } }	 t |  |	 rB t |	  pE d g } n  | | _ d  | _ d  | _ | j | _	 | | _
 | j r | j \ | _ | _	 n  | |  _ | |  _ d  S(   Nt   ,i    (   t
   isinstanceR
   t	   partitiont   intt	   autoscaleR(   R3   t   max_concurrencyt   concurrencyt   min_concurrencyt   no_execvt   autoreload_enabledt   optimization(
   R   R   RE   t
   autoreloadRI   RK   R*   t   max_ct   _t   min_c(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR+      s    '						c         C@  s   | j  r | j  j   n  d  S(   N(   R3   R0   (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR0      s    	c         C@  s   | j  r | j  j   n  d  S(   N(   R3   R2   (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR2      s    	c   	      C@  sD  | j  j j d k r+ t j t t   n  | j } | j } | j	 rP | j
 n t } | s t |  } | _ | j j | _ | j j | _ d } n  |  j p₯ | j } |  j | j | j d | j  | j f d | j d | j d | j d | j oφ | d	 | j d
 | d | d | d | d | d |  j } | _ t | j  | S(   Nt   eventlett   geventid   t   initargst   maxtasksperchildt   timeoutt   soft_timeoutt   putlockst   lost_worker_timeoutt   threadst   max_restartst   allow_restartt   forking_enablet	   semaphoret   sched_strategy(   RP   RQ   (    R4   t   conft   CELERYD_POOLt   warningst   warnt   UserWarningt   W_POOL_SETTINGR   RH   t   force_execvRI   R!   R   R\   t   acquiret   _quick_acquiret   releaset   _quick_releaseRJ   t   pool_restartsR   R   t   hostnamet   max_tasks_per_childt   task_time_limitt   task_soft_time_limitR=   t   worker_lost_waitRK   R3   R   t   task_join_will_block(	   R   R   R\   RY   t   threadedt   procsR[   RZ   R3   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR      s6    
						c         C@  s    i | j  r | j  j n d d 6S(   Ns   N/AR3   (   R3   t   info(   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyRr   ΅   s    c         C@  s   | j  j |  d  S(   N(   R3   t   register_with_event_loop(   R   R   R)   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyRs   Έ   s    N(   R%   R&   R'   R   R:   R(   t   FalseR+   R0   R2   R   Rr   Rs   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   p   s   				c           B@  s/   e  Z d  Z d Z e Z e d  Z d   Z RS(   sl   Step used to embed a beat process.

    This will only be enabled if the ``beat``
    argument is set.

    R   c         K@  s   | |  _  | _ d  | _ d  S(   N(   t   enabledt   beatR(   (   R   R   Rv   R*   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR+   Ζ   s    c         C@  s`   d d l  m } | j j j d  r4 t t   n  | | j d | j d | j	 } | _
 | S(   Ni    (   t   EmbeddedServiceRQ   RP   t   schedule_filenamet   scheduler_cls(   RQ   RP   (   t   celery.beatRw   R   R&   t   endswithR	   t   ERR_B_GREENR4   Rx   Ry   Rv   (   R   R   Rw   t   b(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   Κ   s    	(	   R%   R&   R'   R@   R!   t   conditionalRt   R+   R   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   Ό   s
   c           B@  s    e  Z d  Z d   Z d   Z RS(   s6   This bootstep sets up the workers state db if enabled.c         K@  s   | j  |  _ d  | _ d  S(   N(   t   state_dbRu   R(   t   _persistence(   R   R   R*   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR+   Χ   s    c         C@  s>   | j  j | j  | j | j j  | _ t j | j j  d  S(   N(	   t   statet
   PersistentR   R4   R5   R   t   atexitt   registert   save(   R   R   (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   Ϋ   s    '(   R%   R&   R'   R+   R   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   Τ   s   	c           B@  s   e  Z e Z d    Z RS(   c         C@  sΎ   | j  r% t | j d  | j } n | j | j } |  j | j | j d | j d | j	 d | j
 d | d | j d | j d | j d	 | d
 | j d | j d | j d | j } | _ | S(   Ni   Rj   t   send_eventst   init_callbackt   initial_prefetch_countR3   R   R4   t
   controllerR)   t   worker_optionst   disable_rate_limitst   prefetch_multiplier(   RF   t   maxRH   R   RG   R   t   consumer_clsR<   Rj   R   t   ready_callbackR3   R   R4   R)   t   optionsR   t   consumer(   R   R   t   prefetch_countt   c(    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   γ   s$    										(   R%   R&   R!   t   lastR   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyR   ΰ   s   (%   R'   t
   __future__R    R   R`   t   kombu.asyncR   R-   R   R   t   kombu.async.semaphoreR   R   t   kombu.async.timerR   R   t   celeryR   t   celery._stateR   t   celery.exceptionsR	   t   celery.fiveR
   t   celery.utils.logR   R   t   __all__R|   Rc   t   Stept   StartStopStepR   R   R   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/components.pyt   <module>   s*   %L