Leadership

class chancy.plugins.leadership.ImmediateLeadership[source]

Bases: Plugin

A plugin that simply sets the worker as the leader immediately upon startup.

This plugin is only ever intended for testing purposes, and should not be used in a production environment.

classmethod get_scope() PluginScope[source]

Get the scope of this plugin. Scopes control when and where the plugin will be run.

By default, plugins are scoped to the worker.

async run(worker: Worker, chancy: Chancy)[source]

Runs the plugin.

This function can and should run indefinitely, as it will be cancelled when the worker is stopped.

class chancy.plugins.leadership.Leadership(poll_interval: int = 60, timeout: int = 120)[source]

Bases: Plugin

Leadership is used to ensure some plugins are run by only one worker at a time. For example, we wouldn’t want every worker running database pruning every 60 seconds, as that would be immensely wasteful. Most other plugins require a Leadership plugin to be enabled.

from chancy.plugins.leadership import Leadership

async with Chancy(..., plugins=[
    Leadership()
]) as chancy:
    ...
Parameters:
  • poll_interval – The number of seconds between leadership poll intervals.

  • timeout – The number of seconds before a worker is considered to have lost leadership.

classmethod get_scope() PluginScope[source]

Get the scope of this plugin. Scopes control when and where the plugin will be run.

By default, plugins are scoped to the worker.

async run(worker: Worker, chancy: Chancy)[source]

Runs the plugin.

This function can and should run indefinitely, as it will be cancelled when the worker is stopped.