I started to learn Elixir a couple of days ago and I'm really liking it. Especially the idea of using a Supervisor processes as helpers to create fault-tolerant applications.
However, one scenario that I thought would be natural but I couldn't find any reference so far, is a way of restarting a child process (GenServer) with a different configuration upon a failure.
My use case is the following:
I have a process that grabs data from a Database and works with it to some extent. And the database connection is crucial for the process life. I want to be able to use a different database connection (a backup database) if the process exits abnormally because it could not connect to/fetch data from the database a given N number of times (instead of unleashing hell and throwing notifications that the process is dead because of database connectivity)
Is it possible?
As far as I could see, the Supervisor simply restarts the process the same way every time. Maybe using a :simple_one_for_one strategy could suffice somehow, but I don't know exactly how.