From 89d5ad4f462fe4cc50f975c2e10f6421fabd7c79 Mon Sep 17 00:00:00 2001 From: Florian Jetter Date: Tue, 14 Mar 2023 19:15:06 +0100 Subject: [PATCH] Improve plugin API documentation (#7653) --- distributed/diagnostics/plugin.py | 35 +++++++++++++++++++------------ docs/source/worker-state.rst | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/distributed/diagnostics/plugin.py b/distributed/diagnostics/plugin.py index a577bc8e57e..527b85e1ee4 100644 --- a/distributed/diagnostics/plugin.py +++ b/distributed/diagnostics/plugin.py @@ -24,13 +24,10 @@ class SchedulerPlugin: """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. + A plugin enables custom hooks to run when specific events occur. The scheduler will run the methods of this plugin whenever the corresponding + method of the scheduler is run. 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. @@ -96,6 +93,14 @@ def transition( ) -> None: """Run whenever a task changes state + For a description of the transition mechanism and the available states, + see :ref:`Scheduler task states `. + + .. warning:: + + This is an advanced feature and the transition mechanism and details + of task states are subject to change without deprecation cycle. + Parameters ---------- key : string @@ -131,8 +136,7 @@ class WorkerPlugin: """Interface to extend the Worker A worker plugin enables custom code to run at different stages of the Workers' - lifecycle: at setup, during task state transitions, when a task or dependency - is released, and at teardown. + lifecycle. A plugin enables custom code to run at each of step of a Workers's life. Whenever such an event happens, the corresponding method on this class will be called. Note that the @@ -177,13 +181,18 @@ def teardown(self, worker): def transition(self, key, start, finish, **kwargs): """ - Throughout the lifecycle of a task (see :doc:`Worker `), Workers are - instructed by the scheduler to compute certain tasks, resulting in transitions - in the state of each task. The Worker owning the task is then notified of this - state transition. + Throughout the lifecycle of a task (see :doc:`Worker State + `), Workers are instructed by the scheduler to compute + certain tasks, resulting in transitions in the state of each task. The + Worker owning the task is then notified of this state transition. Whenever a task changes its state, this method will be called. + .. warning:: + + This is an advanced feature and the transition mechanism and details + of task states are subject to change without deprecation cycle. + Parameters ---------- key : string diff --git a/docs/source/worker-state.rst b/docs/source/worker-state.rst index ca53cbc625e..3cacc517d09 100644 --- a/docs/source/worker-state.rst +++ b/docs/source/worker-state.rst @@ -1,3 +1,4 @@ +.. _worker-state: Worker State Machine ====================