I have a problem when I want to supervise user-defined jobs.
Jobs have steps and between steps, I am saving the last known finished state.
In the case of a node restart, I am reading that info from DB and resume.
I started by using DynamicSupervisor with Task for each user-specified job.
The problem is that when the job is ill-defined. It can fail immediately.
I want to restart it three times and after that give up.
However, I don’t want to kill the entire DynamicSupervisor with it because other tasks are perfectly fine.
I decided, I’ll change the hierarchy.
DynamicSupervisorOfSupervisors `- JobSupervisor (one_for_one, restart: :temporary) (don't restart it if it crashes; crash means that Worker crashed quickly in succession so we want to give up) `- ActualWorker (restart: :transient) (restart if it fails)
That solves one problem because now I don’t crash DynamicSupervisor and restarts work fine. But when the job finishes normally, I am left with dangling
JobSupervisor that has nothing to supervise but didn’t crash.
Is there an elegant solution for spawning a supervisor that finishes with its last finished child?