View Source Solo (solo v0.4.2)

Solo is the library to turn parts of the existing supervision trees into singletons.

Consider the application having the following children specified somewhere in the supervision tree.

children = [
  Foo,
  {Bar, [bar_arg]},
  {Baz, [baz_arg]},
  ...
]

and there is a necessity to make Bar and Baz processes singletons across the cluster. Simply wrap the specs in question into Solo.global/2 and you are all set.

children = [
  Foo,
  Solo.global(SoloBarBaz, [
    {Bar, [bar_arg]},
    {Baz, [baz_arg]}
  ],
  ...
]

Summary

Interface

Helper to make parts of the supervision tree a global distributed singleton.

Shenanigans

Returns the state of the Solo from this node’s perspective (pids of workers might be remote.)

Looks the process with the name given as the first parameter up.

Interface

Link to this function

global(name \\ __MODULE__, children, opts \\ [timer: 1000])

View Source

Helper to make parts of the supervision tree a global distributed singleton.

Simply wrap the parts of any supervision tree with a call to Solo.global/2 and you ar eall set.

children = [
  Foo,
  Solo.global(SoloBarBaz, [
    {Bar, [bar_arg]},
    {Baz, [baz_arg]}
  ],
  ...
]

The name (SoloBarBaz) above might be used later to check the state of the running Solo supervisor with Solo.state/1, although this is usually not a demanded feature.

To lookup the named processes turned into Solo, use Solo.whereis/1, passing the respective id (SoloBarBaz) and the actual name of the process.

Shenanigans

Link to this function

state(solo \\ __MODULE__)

View Source
@spec state(solo :: atom()) :: %{
  name: atom(),
  supervisor: pid(),
  pg: reference(),
  workers: %{optional(pid()) => atom()}
}

Returns the state of the Solo from this node’s perspective (pids of workers might be remote.)

@spec whereis(name :: atom()) :: pid()

Looks the process with the name given as the first parameter up.