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``.
>>> 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
State of the released dependency. One of waiting, flight, memory.
Whether the worker should report the released dependency to the scheduler.
This method is overriden in:
State of the released task. One of waiting, ready, executing, long-running, memory, error.
Additional information on what triggered the release of the task.
Not used.
Whether the worker should report the released task to the scheduler.
This method is overriden in:
This method is overriden in:
This method is overriden in:
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.
Start state of the transition. One of waiting, ready, executing, long-running, memory, error.
Final state of the transition.
This method is overriden in: