๓
P'^c           @@  sฐ   d  Z  d d l m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d	 d
 g Z d Z d   Z d e f d     YZ d	 e f d     YZ d S(   s   
    celery.app.control
    ~~~~~~~~~~~~~~~~~~~

    Client for worker remote control commands.
    Server implementation is in :mod:`celery.worker.control`.

i    (   t   absolute_importN(   t   Mailbox(   t   cached_property(   t   DuplicateNodenameWarning(   t	   pluralizet   Inspectt   Controlt   flatten_replysz   Received multiple replies from node {0}: {1}.
Please make sure you give each node a unique nodename using the `-n` option.c         C@  sค   i  t    } } xG |  D]? } g  | D]! } | | k r$ | j |  ^ q$ | j |  q W| r  t j t t j t t	 |  d  d j
 t |      n  | S(   Nt   names   , (   t   sett   addt   updatet   warningst   warnR   t	   W_DUPNODEt   formatR   t   lent   joint   sorted(   t   replyt   nodest   dupest   itemR   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR      s    ,	1c           B@  s์   e  Z d Z d d  d d d d d  Z d   Z d   Z d   Z d   Z e	 d  Z
 e	 d  Z e	 d  Z d	   Z d
   Z d   Z e Z d   Z d   Z d   Z e	 d  Z d d  Z d   Z d d  Z d d d d  Z RS(   i   c         C@  sC   | p |  j  |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   appt   destinationt   timeoutt   callbackt
   connectiont   limit(   t   selfR   R   R   R   R   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   __init__-   s    				c         C@  sL   | s
 d  St  |  } |  j rH t |  j t t f  rH | j |  j  S| S(   N(   R   R   t
   isinstancet   listt   tuplet   get(   R   R   t   by_node(    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   _prepare6   s    	c         K@  sU   |  j  |  j j j | d | d |  j d |  j d |  j d |  j d |  j d t	  S(   Nt	   argumentsR   R   R   R   R   R   (
   R$   R   t   controlt	   broadcastR   R   R   R   R   t   True(   R   t   commandt   kwargs(    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   _request?   s    				c         C@  s   |  j  d  S(   Nt   report(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR,   J   s    c         C@  s   |  j  d  S(   Nt   clock(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR-   M   s    c         C@  s   |  j  d d | S(   Nt   dump_activet   safe(   R+   (   R   R/   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   activeP   s    c         C@  s   |  j  d d | S(   Nt   dump_scheduleR/   (   R+   (   R   R/   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt	   scheduledS   s    c         C@  s   |  j  d d | S(   Nt   dump_reservedR/   (   R+   (   R   R/   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   reservedV   s    c         C@  s   |  j  d  S(   Nt   stats(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR5   Y   s    c         C@  s   |  j  d  S(   Nt   dump_revoked(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   revoked\   s    c         G@  s   |  j  d d | S(   Nt
   dump_taskst   taskinfoitems(   R+   (   R   R9   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt
   registered_   s    c         C@  s   |  j  d  S(   Nt   ping(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR;   c   s    c         C@  s   |  j  d  S(   Nt   active_queues(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR<   f   s    c         C@  s   |  j  d d | S(   Nt
   query_taskt   ids(   R+   (   R   R>   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR=   i   s    c         C@  s   |  j  d d | S(   Nt	   dump_conft   with_defaults(   R+   (   R   R@   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   confl   s    c         C@  s   |  j  d d | d | S(   Nt   hellot	   from_nodeR7   (   R+   (   R   RC   R7   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRB   o   s    c         C@  s   |  j  d  S(   Nt	   memsample(   R+   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRD   r   s    i
   c         C@  s   |  j  d d | S(   Nt   memdumpt   samples(   R+   (   R   RF   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRE   u   s    t   Requestiศ   c         C@  s   |  j  d d | d | d | S(   Nt   objgrapht   numt	   max_deptht   type(   R+   (   R   RK   t   nRJ   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRH   x   s    N(   t   __name__t
   __module__t   NoneR   R   R$   R+   R,   R-   t   FalseR0   R2   R4   R5   R7   R:   t   registered_tasksR;   R<   R=   RA   RB   RD   RE   RH   (    (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR   *   s,   													c        	   B@  s  e  Z e Z d d   Z e d    Z d d  Z e Z d d d  Z	 d e
 d d  Z d d d  Z d d  Z d d	 d d d
  Z d   Z d d d  Z d d  Z d d  Z d d d  Z d d d  Z d d  Z d d d e
 d d d d d  Z RS(   c         C@  s.   | |  _  |  j d d d d d g |  _ d  S(   Nt   celeryRK   t   fanoutt   acceptt   json(   R   R   t   mailbox(   R   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR      s    	c         C@  s   |  j  j t d d S(   Nt   reverses   control.inspect(   R   t   subclass_with_selfR   (   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   inspect   s    c         C@  s8   |  j  j |    } |  j  j j |  j   SWd QXd S(   sอ   Discard all waiting tasks.

        This will ignore all tasks waiting for execution, and they will
        be deleted from the messaging server.

        :returns: the number of tasks discarded.

        N(   R   t   connection_or_acquiret   amqpt   TaskConsumert   purge(   R   R   t   conn(    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR]      s    	c         C@  s2   |  j  d d | d i | d 6| d 6| d 6d  S(   Nt   electionR   R%   t   idt   topict   action(   R'   (   R   R`   Ra   Rb   R   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR_      s    t   SIGTERMc         K@  s1   |  j  d d | d i | d 6| d 6| d 6| S(   s๊  Tell all (or specific) workers to revoke a task by id.

        If a task is revoked, the workers will ignore the task and
        not execute it after all.

        :param task_id: Id of the task to revoke.
        :keyword terminate: Also terminate the process currently working
            on the task (if any).
        :keyword signal: Name of signal to send to process if terminate.
            Default is TERM.

        See :meth:`broadcast` for supported keyword arguments.

        t   revokeR   R%   t   task_idt	   terminatet   signal(   R'   (   R   Re   R   Rf   Rg   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRd      s    
i   c      	   K@  s"   |  j  d d t d | d | | S(   s   Ping all (or specific) workers.

        Will return the list of answers.

        See :meth:`broadcast` for supported keyword arguments.

        R;   R   R   R   (   R'   R(   (   R   R   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR;   ฎ   s    c         K@  s*   |  j  d d | d i | d 6| d 6| S(   sซ  Tell all (or specific) workers to set a new rate limit
        for task by type.

        :param task_name: Name of task to change rate limit for.
        :param rate_limit: The rate limit as tasks per second, or a rate limit
            string (`'100/m'`, etc.
            see :attr:`celery.task.base.Task.rate_limit` for
            more information).

        See :meth:`broadcast` for supported keyword arguments.

        t
   rate_limitR   R%   t	   task_name(   R'   (   R   Ri   Rh   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRh   น   s    
t   directc         K@  sA   |  j  d d t i | d 6| d 6| d 6| d 6| p7 i   | S(   s`  Tell all (or specific) workers to start consuming from a new queue.

        Only the queue name is required as if only the queue is specified
        then the exchange/routing key will be set to the same name (
        like automatic queues do).

        .. note::

            This command does not respect the default queue/exchange
            options in the configuration.

        :param queue: Name of queue to start consuming from.
        :keyword exchange: Optional name of exchange.
        :keyword exchange_type: Type of exchange (defaults to 'direct')
            command to, when empty broadcast to all workers.
        :keyword routing_key: Optional routing key.
        :keyword options: Additional options as supported
            by :meth:`kombu.entitiy.Queue.from_dict`.

        See :meth:`broadcast` for supported keyword arguments.

        t   add_consumerR%   t   queuet   exchanget   exchange_typet   routing_key(   R'   t   dict(   R   Rl   Rm   Rn   Ro   t   optionsR*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRk   ห   s    c         K@  s   |  j  d d i | d 6| S(   s   Tell all (or specific) workers to stop consuming from ``queue``.

        Supports the same keyword arguments as :meth:`broadcast`.

        t   cancel_consumerR%   Rl   (   R'   (   R   Rl   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRr   ๋   s    c         K@  s+   |  j  d d i | d 6| d 6| d 6| S(   sZ  Tell all (or specific) workers to set time limits for
        a task by type.

        :param task_name: Name of task to change time limits for.
        :keyword soft: New soft time limit (in seconds).
        :keyword hard: New hard time limit (in seconds).

        Any additional keyword arguments are passed on to :meth:`broadcast`.

        t
   time_limitR%   Ri   t   hardt   soft(   R'   (   R   Ri   Ru   Rt   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRs   ๕   s    
c         K@  s   |  j  d i  | |  S(   s0   Tell all (or specific) workers to enable events.t   enable_events(   R'   (   R   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRv     s    c         K@  s   |  j  d i  | |  S(   s1   Tell all (or specific) workers to disable events.t   disable_events(   R'   (   R   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRw   	  s    c         K@  s   |  j  d i | d 6| |  S(   s~   Tell all (or specific) workers to grow the pool by ``n``.

        Supports the same arguments as :meth:`broadcast`.

        t	   pool_growRL   (   R'   (   R   RL   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRx     s    c         K@  s   |  j  d i | d 6| |  S(   s   Tell all (or specific) workers to shrink the pool by ``n``.

        Supports the same arguments as :meth:`broadcast`.

        t   pool_shrinkRL   (   R'   (   R   RL   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRy     s    c         K@  s$   |  j  d i | d 6| d 6| |  S(   sh   Change worker(s) autoscale setting.

        Supports the same arguments as :meth:`broadcast`.

        t	   autoscalet   maxt   min(   R'   (   R   R{   R|   R   R*   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyRz     s    c
         K@  sb   |  j  j |  J } t | p! i  |
  } |  j |  j | | | | | | | d |	 SWd QXd S(   sผ  Broadcast a control command to the celery workers.

        :param command: Name of command to send.
        :param arguments: Keyword arguments for the command.
        :keyword destination: If set, a list of the hosts to send the
            command to, when empty broadcast to all workers.
        :keyword connection: Custom broker connection to use, if not set,
            a connection will be established automatically.
        :keyword reply: Wait for and return the reply.
        :keyword timeout: Timeout in seconds to wait for the reply.
        :keyword limit: Limit number of replies.
        :keyword callback: Callback called immediately for each reply
            received.

        t   channelN(   R   RZ   Rp   RV   t
   _broadcast(   R   R)   R%   R   R   R   R   R   R   R}   t   extra_kwargsR^   (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR'   &  s
    N(   RM   RN   R   RO   R   R   RY   R]   t   discard_allR_   RP   Rd   R;   Rh   Rk   Rr   Rs   Rv   Rw   Rx   Ry   Rz   R'   (    (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyR   |   s,   	
	(   t   __doc__t
   __future__R    R   t   kombu.pidboxR   t   kombu.utilsR   t   celery.exceptionsR   t   celery.utils.textR   t   __all__R   R   t   objectR   R   (    (    (    s4   /tmp/pip-unpacked-wheel-gV1wwp/celery/app/control.pyt   <module>	   s   	R