Exclusive Periodic Task in Elixir Cluster

This does what you were trying to do: Singleton - global, supervised singleton processes for Elixir

The key is to do the name registration after the process starts, and then branch on the result:

  • If the registration succeeds, act as the “master”, running the periodic tasks
  • If it fails, then act as “follower” and just monitor the master. Once the master dies, try to take its place.