Runs a process once per cluster.
Add it to a mount's children to run one instance of a process across all nodes, such as a scheduler that must not run twice:
def children(mount) do
[
{PhoenixMountable.Singleton,
name: {:refresh_scheduler, PhoenixMountable.Mount.key(mount)},
child: {MyLib.RefreshScheduler, mount: mount}}
]
endEvery node runs a Singleton. The first to register :name globally owns
it and starts the child; the others watch the owner. When the owner's node
goes down, the next one registers and starts the child. A child that exits
is restarted by its owner. On a single node it simply runs the child.
whereis/1 returns the child, on whichever node it runs.
Options
:name(required) — a term naming the singleton across the cluster.:child(required) — the child spec of the process.:retry— milliseconds before restarting a child that failed to start or exited. Defaults to1_000.
Summary
Functions
The pid of the singleton's child named name, on any node, or nil.