ó
P'—^c           @@  s¬  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l 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
 d d d d d d d d d d d g Z i d d 6e d 6e j ƒ  d 6Z d Z d Z e ƒ  Z e ƒ  Z e ƒ  Z d g Z e d e d e ƒ Z  e j! Z" e# Z$ e# Z% d „  Z& d „  Z' e d „ Z( d „  Z) e j* j+ d  ƒ p«e j* j+ d! ƒ Z, e- e j* j+ d" ƒ pØe j* j+ d# ƒ pØd$ ƒ Z. e, r’d d l/ Z/ d d% l0 m1 Z1 d d& l m2 Z2 d d' l3 m4 Z4 m5 Z5 d a6 d a8 d a9 d a: e. Z; g  Z< e" Z= e) Z> e1 ƒ  j? d( k r}e/ j@ d) „  ƒ ZA n  d* „  Z" d+ „  Z) n  d eB f d, „  ƒ  YZC d S(-   sµ   
    celery.worker.state
    ~~~~~~~~~~~~~~~~~~~

    Internal worker state (global)

    This includes the currently active and reserved tasks,
    statistics, and revoked tasks.

i    (   t   absolute_importN(   t   picklet   pickle_protocol(   t   cached_property(   t   __version__(   t
   LimitedSet(   t   WorkerShutdownt   WorkerTerminate(   t   Countert   SOFTWARE_INFOt   reserved_requestst   active_requestst   total_countt   revokedt   task_reservedt   maybe_shutdownt   task_acceptedt
   task_readyt
   Persistents	   py-celeryt   sw_identt   sw_vert   sw_sysiPÃ  i0*  t   maxlent   expiresc           C@  s6   t  j ƒ  t j ƒ  t j ƒ  d g t (t j ƒ  d  S(   Ni    (   R
   t   clearR   R   t   all_total_countR   (    (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyt   reset_stateC   s
    



c           C@  s(   t  r t ƒ  ‚ n t r$ t ƒ  ‚ n  d  S(   N(   t   should_stopR   t   should_terminateR   (    (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   K   s    c         C@  s4   t  j |  ƒ t |  j c d 7<t d c d 7<d S(   s3   Updates global state when a task has been accepted.i   i    N(   R   t   addR   t   nameR   (   t   requestt   _all_total_count(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   R   s    c         C@  s   t  j |  ƒ t j |  ƒ d S(   s*   Updates global state when a task is ready.N(   R   t   discardR
   (   R   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   Y   s    t   C_BENCHt   CELERY_BENCHt   C_BENCH_EVERYt   CELERY_BENCH_EVERYiè  (   t   current_process(   t	   monotonic(   t   memdumpt
   sample_memt   MainProcessc           C@  sV   t  d  k	 rR t d  k	 rR d j t t  ƒ GHd j t t ƒ t t ƒ ƒ GHt ƒ  n  d  S(   Ns    - Time spent in benchmark: {0!r}s
   - Avg: {0}(   t   bench_firstt   Nonet
   bench_lastt   formatt   sumt   bench_samplet   lenR(   (    (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyt   on_shutdowns   s    c         C@  sA   d  } t d  k r" t ƒ  a } n  t d  k r7 | a n  t |  ƒ S(   N(   R,   t   bench_startR'   R+   t
   __reserved(   R   t   now(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   |   s    	c         C@  sp   t  d 7a  t  t sf t ƒ  } | t } d j t | ƒ GHt j j ƒ  | a a t	 j
 | ƒ t ƒ  n  t |  ƒ S(   Ni   sI   - Time spent processing {0} tasks (since first task received): ~{1:.4f}s
(   t	   all_countt   bench_everyR'   R3   R.   t   syst   stdoutt   flushR-   R0   t   appendR)   t   __ready(   R   R5   t   diff(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   ‡   s    

	


c           B@  sÑ   e  Z d  Z e Z e Z e j Z e j	 Z	 e
 Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   s   This is the persistent data stored by the worker when
    :option:`--statedb` is enabled.

    It currently only stores revoked task id's.

    c         C@  s)   | |  _  | |  _ | |  _ |  j ƒ  d  S(   N(   t   statet   filenamet   clockt   merge(   t   selfR>   R?   R@   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyt   __init__¥   s    			c         C@  s"   |  j  j |  j d |  j d t ƒS(   Nt   protocolt	   writeback(   t   storaget   openR?   RD   t   True(   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRG   «   s    	c         C@  s   |  j  |  j ƒ d  S(   N(   t   _merge_witht   db(   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRA   °   s    c         C@  s!   |  j  |  j ƒ |  j j ƒ  d  S(   N(   t
   _sync_withRJ   t   sync(   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRL   ³   s    c         C@  s&   |  j  r" |  j j ƒ  t |  _  n  d  S(   N(   t   _is_openRJ   t   closet   False(   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRN   ·   s    	c         C@  s   |  j  ƒ  |  j ƒ  d  S(   N(   RL   RN   (   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyt   save¼   s    
c         C@  s   |  j  | ƒ |  j | ƒ | S(   N(   t   _merge_revokedt   _merge_clock(   RB   t   d(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRI   À   s    c         C@  sZ   |  j  j ƒ  | j d d d |  j |  j |  j  ƒ ƒ d |  j rO |  j j ƒ  n d ƒ | S(   Nt	   __proto__i   t   zrevokedR@   i    (   t   _revoked_taskst   purget   updatet   compresst   _dumpsR@   t   forward(   RB   RS   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRK   Å   s    	c         C@  s5   |  j  r1 |  j  j | j d ƒ p$ d ƒ | d <n  d  S(   NR@   i    (   R@   t   adjustt   get(   RB   RS   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRR   Î   s    	c         C@  sh   y |  j  | d ƒ Wn? t k
 rV y |  j | j d ƒ ƒ WqW t k
 rR qW Xn X|  j j ƒ  d  S(   NRU   R   (   t   _merge_revoked_v3t   KeyErrort   _merge_revoked_v2t   popRV   RW   (   RB   RS   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRQ   Ò   s    c         C@  s/   | r+ |  j  j t j |  j | ƒ ƒ ƒ n  d  S(   N(   RV   RX   R   t   loadst
   decompress(   RB   RU   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR^   Ý   s    c         C@  s0   t  | t ƒ s |  j | ƒ S|  j j | ƒ d  S(   N(   t
   isinstanceR   t   _merge_revoked_v1RV   RX   (   RB   t   saved(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR`   á   s    c         C@  s+   |  j  j } x | D] } | | ƒ q Wd  S(   N(   RV   R   (   RB   Rf   R   t   item(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRe   ç   s    c         C@  s   t  j | d |  j ƒS(   NRD   (   R   t   dumpsRD   (   RB   t   obj(    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRZ   ì   s    c         C@  s
   |  j  j S(   N(   R>   R   (   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRV   ï   s    c         C@  s   t  |  _ |  j ƒ  S(   N(   RH   RM   RG   (   RB   (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyRJ   ó   s    	N(   t   __name__t
   __module__t   __doc__t   shelveRF   R   RD   t   zlibRY   Rc   RO   RM   R,   RC   RG   RA   RL   RN   RP   RI   RK   RR   RQ   R^   R`   Re   RZ   t   propertyRV   R   RJ   (    (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyR   ˜   s,   																(D   Rl   t
   __future__R    t   osR8   t   platformRm   Rn   t   kombu.serializationR   R   t   kombu.utilsR   t   celeryR   t   celery.datastructuresR   t   celery.exceptionsR   R   t   celery.fiveR   t   __all__t   systemR	   t   REVOKES_MAXt   REVOKE_EXPIRESt   setR
   R   R   R   R   R   R   RO   R   R   R   R   R   R   t   environR]   R"   t   intR$   t   atexitt   billiardR&   R'   t   celery.utils.debugR(   R)   R6   R,   R+   R3   R-   R7   R0   R4   R<   t   _namet   registerR2   t   objectR   (    (    (    s5   /tmp/pip-unpacked-wheel-gV1wwp/celery/worker/state.pyt   <module>   sl   		
								$		