Class WorkerPlugin

Interface to extend the Worker

Declaration

class WorkerPlugin
source link

Documentation

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.

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
user code always runs within the Worker's main thread.

To implement a plugin implement some of the methods of this class and register
the plugin to your client in order to have it attached to every existing and
future workers with ``Client.register_worker_plugin``.

Examples

>>> class ErrorLogger(WorkerPlugin):
...     def __init__(self, logger):
...         self.logger = logger
...
...     def setup(self, worker):
...         self.worker = worker
...
...     def transition(self, key, start, finish, *args, **kwargs):
...         if finish == 'error':
...             exc = self.worker.exceptions[key]
...             self.logger.error("Task '%s' has failed with exception: %s" % (key, str(exc)))

>>> plugin = ErrorLogger()
>>> client.register_worker_plugin(plugin)  # doctest: +SKIP

Methods

Subclasses

Reexports