Skip to content

nomasystems/nbully

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nbully

An OTP application for leader election.

The nbully application starts a supervisor that supervises a worker process. This process runs in every node and consensuates node leadership with its homologues in other nodes.

Status

GitHub branch checks state

Prerequisites

Min. OTP version Max. OTP version Min. rebar version

Usage

In your rebar.config file, add the dependency:

{deps, [
    {nbully, {git, "git@github.com:nomasystems/nbully.git", {branch, "main"}}}
]}.

Then, once the application is started, you can consult nbully:leader/0 to know which node is the current leader. This value is the same for all nodes connected through net_kernel and might only change when nodes go up or down.

You can also use nbully:subscribe/0 to receive live updates when the leader changes in the form of a message {nbully_leader_update, Node}. For example:

ok = nbully:subscribe(),
InitialLeader = nbully:leader(),
% [...]
NewLeader =
  receive
    {nbully_leader_update, Node} -> Node
  after 1000 -> InitialLeader
end,
LeaderIsMe = node() =:= NewLeader,
% [...]
ok = nbully:unsubscribe().

Support

Any doubt or suggestion? Please, check out our issue tracker.

Contributing

Pull requests are welcome. Please read the contributing guidelines to know more about contribution.