How to hold a reference to a process even after it is restarted?

I did not say Room Worker Supervisor is responsible for restarting Room processes.
I said The Room Worker Supervisor is as dumb as possible.

You should be able to differentiate between a crash and a normal exit. For example, after someone wins the game, it should not be restarted.

You can achieve this by

  • Setting workers to temporary
  • Monitor workers from manager
  • Trap exit in manager
  • Check if exit is normal, or not
    • normal -> cleanup state, maybe persist game in db
    • abnormal -> restart worker from manager, using dynamic supervisor

The manager can also link consumer processes… thus it can detect when a consumer goes down.

There is a similar example in this book describing poolboy library. Although not to date, the example is using single_one_for_one instead of dynamic supervisor, it is very instructive.

Often You will see this combination of top supervisor, manager, worker supervisor, workers, like in this picture…

And it is kind of fractal, because each workers could potentially be another combination of supervisor, manager, worker supervisor, workers…

I recommend this video if You are interested in game server.

1 Like