kazoo.recipe.election¶
ZooKeeper Leader Elections
Maintainer: | None |
---|---|
Status: | Unknown |
Public API¶
- class kazoo.recipe.election.Election(client, path, identifier=None)[source]¶
Kazoo Basic Leader Election
Example usage with a KazooClient instance:
zk = KazooClient() election = zk.Election("/electionpath", "my-identifier") # blocks until the election is won, then calls # my_leader_function() election.run(my_leader_function)
- __init__(client, path, identifier=None)[source]¶
Create a Kazoo Leader Election
Parameters:
- client – A KazooClient instance.
- path – The election path to use.
- identifier – Name to use for this lock contender. This can be useful for querying to see who the current lock contenders are.
- cancel()[source]¶
Cancel participation in the election
Note
If this contender has already been elected leader, this method will not interrupt the leadership function.
- contenders()[source]¶
Return an ordered list of the current contenders in the election
Note
If the contenders did not set an identifier, it will appear as a blank string.
- run(func, *args, **kwargs)[source]¶
Contend for the leadership
This call will block until either this contender is cancelled or this contender wins the election and the provided leadership function subsequently returns or fails.
Parameters:
- func – A function to be called if/when the election is won.
- args – Arguments to leadership function.
- kwargs – Keyword arguments to leadership function.