bitwalker / swarm

Easy clustering, registration, and distribution of worker processes for Erlang/Elixir
MIT License
1.2k stars 103 forks source link

Include a restart parameter #139

Open balena opened 4 years ago

balena commented 4 years ago

So Swarm.Tracker can figure out what is intended to happen on :DOWN message.

Basically the version 3.4.0 this change is based on ignores handoffs when the reason isn’t :noconnection (node down event); but this is bad when you do need a handoff during “graceful shutdowns”.

The restart parameter will assume the same values as those passed to Supervisor child spec: if :permanent then a handoff will occur always, if :transient only if the terminate reason is other than :normal | :shutdown | {:shutdown, term}, and if :temporary then it is never restarted, only when the node is down (that's the normal old behaviour which is assumed by default).

That's the same idea described on Supervisor / Restart values but applied to a cluster.

balena commented 4 years ago

Indicating that the process should have a lifetime that surpasses the natural logic of a regular GenServer means that we're probably willing to adopt a restart: :permanent policy, just like a Supervisor does https://github.com/bitwalker/swarm/issues/117

balena commented 4 years ago

This PR also solves https://github.com/bitwalker/swarm/issues/11 as the indicated solution of using Swarm.Tracker not always work (needs synchronization when terminating the app or there is no handoff at all).