B
    °F.\}	  ã               @   s:   d dl mZmZmZ d dlZe e¡ZG dd„ deƒZ	dS )é    )Úprint_functionÚdivisionÚabsolute_importNc               @   s>   e Zd ZdZddd„Zdd„ Zdd„ Zdd	d
„Zddd„ZdS )ÚSchedulerPluginaÞ   Interface to extend the Scheduler

    The scheduler operates by triggering and responding to events like
    ``task_finished``, ``update_graph``, ``task_erred``, etc..

    A plugin enables custom code to run at each of those same events.  The
    scheduler will run the analogous methods on this class when each event is
    triggered.  This runs user code within the scheduler thread that can
    perform arbitrary operations in synchrony with the scheduler itself.

    Plugins are often used for diagnostics and measurement, but have full
    access to the scheduler and could in principle affect core scheduling.

    To implement a plugin implement some of the methods of this class and add
    the plugin to the scheduler with ``Scheduler.add_plugin(myplugin)``.

    Examples
    --------
    >>> class Counter(SchedulerPlugin):
    ...     def __init__(self):
    ...         self.counter = 0
    ...
    ...     def transition(self, key, start, finish, *args, **kwargs):
    ...         if start == 'processing' and finish == 'memory':
    ...             self.counter += 1
    ...
    ...     def restart(self, scheduler):
    ...         self.counter = 0

    >>> c = Counter()
    >>> scheduler.add_plugin(c)  # doctest: +SKIP
    Nc             K   s   dS )z2 Run when a new graph / tasks enter the scheduler N© )ÚselfÚ	schedulerZdskÚkeysZrestrictionsÚkwargsr   r   ú=lib/python3.7/site-packages/distributed/diagnostics/plugin.pyÚupdate_graph*   s    zSchedulerPlugin.update_graphc             K   s   dS )z( Run when the scheduler restarts itself Nr   )r   r   r
   r   r   r   Úrestart.   s    zSchedulerPlugin.restartc             O   s   dS )a¥   Run whenever a task changes state

        Parameters
        ----------
        key: string
        start: string
            Start state of the transition.
            One of released, waiting, processing, memory, error.
        finish: string
            Final state of the transition.
        *args, **kwargs: More options passed when transitioning
            This may include worker ID, compute time, etc.
        Nr   )r   ÚkeyÚstartZfinishÚargsr
   r   r   r   Ú
transition1   s    zSchedulerPlugin.transitionc             K   s   dS )z* Run when a new worker enters the cluster Nr   )r   r   Úworkerr
   r   r   r   Ú
add_worker@   s    zSchedulerPlugin.add_workerc             K   s   dS )z% Run when a worker leaves the clusterNr   )r   r   r   r
   r   r   r   Úremove_workerC   s    zSchedulerPlugin.remove_worker)NNN)NN)NN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r      s     

r   )
Z
__future__r   r   r   ZloggingZ	getLoggerr   ZloggerÚobjectr   r   r   r   r   Ú<module>   s   
