View Source Solo    Kantox ❤ OSS  Test  Dialyzer

Objective

This library might be handy when one needs to keep a singleton across the cluster with zero downtime. Consider the application needs to collect some data from the external source when the only one connection is allowed. If for some reason the node running a connection goes down, the takeover from other node should have happened. In the old good days we used native erlang failover/takeover mechanism for that, but nowadays in the cloud any container might go down unexpectedly due to some internal considerations of ECS.

In such a case the application would need to immediately restart the connection on one of the nodes still alive. This library transparently makes it possible to turn any number of processes in the supervision tree into such singletons without writing much code.

Simply wrap the specs into Solo.global/2 call and you are all set.

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

Implementation

The library uses both Process.monitor/1 and :pg.monitor/1 to get acknowledged about disappeared processes. Each node carries the state of the monitored cluster to restart processes on some of the still alive nodes when necessary.

Solo is backed by Supervisor, unlike e. g. Singleton, which uses DynamicSupervisor, allowing for next to zero boilerplate and resurrection from brutal VM crashes.

Installation

The package can be installed by adding solo to your list of dependencies in mix.exs:

def deps do
  [
    {:solo, "~> 0.1"}
  ]
end

FAQ

  • Is it of any good? — Sure it is.
  • Would it work for me? — Well, it works on my machine.

Documentation