ó
P'—^c           @@  sæ   d  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 g Z e d ƒ Z d e f d „  ƒ  YZ d d d d d d d d „ Z d S(   sx  
    celery.events.snapshot
    ~~~~~~~~~~~~~~~~~~~~~~

    Consuming the events as a stream is not always suitable
    so this module implements a system to take snapshots of the
    state of a cluster at regular intervals.  There is a full
    implementation of this writing the snapshots to a database
    in :mod:`djcelery.snapshots` in the `django-celery` distribution.

i    (   t   absolute_import(   t   TokenBucket(   t	   platforms(   t   app_or_default(   t   Timer(   t   Signal(   t   instantiate(   t
   get_logger(   t   ratet   Polaroidt   evcams   celery.evcamc           B@  s¡   e  Z d Z e d  d ƒ Z e ƒ  Z e Z d Z	 d Z
 d d d d d d „ Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   t   providing_argst   stateg      ð?g      ¬@c         C@  sm   t  | ƒ |  _ | |  _ | |  _ | |  _ | p? |  j p? t ƒ  |  _ t |  _ | oc t t	 | ƒ ƒ |  _
 d  S(   N(   R   t   appR   t   freqt   cleanup_freqt   timerR   t   loggerR   R   t   maxrate(   t   selfR   R   R   R   R   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt   __init__'   s    				c         C@  s@   |  j  j |  j |  j ƒ |  _ |  j  j |  j |  j ƒ |  _ d  S(   N(   R   t   call_repeatedlyR   t   capturet   _trefR   t   cleanupt   _ctref(   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt   install1   s    	c         C@  s   d  S(   N(    (   R   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt
   on_shutter7   s    c         C@  s   d  S(   N(    (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt
   on_cleanup:   s    c         C@  s+   t  j d ƒ |  j j d  ƒ |  j ƒ  d  S(   Ns   Cleanup: Running...(   R   t   debugt   cleanup_signalt   sendt   NoneR   (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyR   =   s    c         C@  s[   |  j  d  k s |  j  j ƒ  rW t j d |  j ƒ |  j j |  j ƒ |  j |  j ƒ n  d  S(   Ns   Shutter: %s(	   R   R    t   can_consumeR   R   R   t   shutter_signalR   R   (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt   shutterB   s    c         C@  s    |  j  j |  j d |  j ƒd  S(   Nt   clear_after(   R   t   freeze_whileR#   R$   (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyR   H   s    c         C@  s@   |  j  r# |  j  ƒ  |  j  j ƒ  n  |  j r< |  j j ƒ  n  d  S(   N(   R   t   cancelR   (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyR&   K   s
    	
	c         C@  s   |  j  ƒ  |  S(   N(   R   (   R   (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt	   __enter__R   s    
c         G@  s   |  j  ƒ  d  S(   N(   R&   (   R   t   exc_info(    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt   __exit__V   s    N(   R   (   t   __name__t
   __module__R    R   R   R"   R   t   FalseR$   R   R   R   R   R   R   R   R#   R   R&   R'   R)   (    (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyR	      s"   										g      ð?c         C@  s  t  | ƒ } | r" t j | ƒ n  | j j | | ƒ d j |  | ƒ GH| j j ƒ  } t |  | d | d | d | d | ƒ}	 |	 j	 ƒ  | j
 ƒ  }
 | j j |
 d i | j d 6ƒ} z2 y | j d d  ƒ Wn t k
 rä t ‚ n XWd  |	 j ƒ  |
 j ƒ  Xd  S(	   Ns5   -> evcam: Taking snapshots with {0} (every {1} secs.)R   R   R   R   t   handlerst   *t   limit(   R   R   t   create_pidlockt   logt   setup_logging_subsystemt   formatt   eventst   StateR   R   t
   connectiont   Receivert   eventR   R    t   KeyboardInterruptt
   SystemExitR&   t   close(   t   cameraR   R   t   loglevelt   logfilet   pidfileR   R   R   t   camt   connt   recv(    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyR
   Z   s&    
"
N(   t   __doc__t
   __future__R    t   kombu.utils.limitsR   t   celeryR   t
   celery.appR   t   celery.utils.timer2R   t   celery.utils.dispatchR   t   celery.utils.importsR   t   celery.utils.logR   t   celery.utils.timeutilsR   t   __all__R   t   objectR	   R    R
   (    (    (    s8   /tmp/pip-unpacked-wheel-gV1wwp/celery/events/snapshot.pyt   <module>   s   <	