Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve plugin API documentation #7653

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions distributed/diagnostics/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <scheduler-task-state>`.

.. 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -177,13 +181,18 @@ def teardown(self, worker):

def transition(self, key, start, finish, **kwargs):
"""
Throughout the lifecycle of a task (see :doc:`Worker <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
<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
Expand Down
1 change: 1 addition & 0 deletions docs/source/worker-state.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. _worker-state:
Worker State Machine
====================

Expand Down