I'm not an OTP expert but the simplest solution to something like that would probably be to set up a second process in the supervisor that would monitor the failing process and do the work (like saving reason to db or issue some notification).
This way concerns are nicely separated between application structure (supervisors) and reacting to process lifetime events.
So in the Supervisor worker spec, make sure that the shutdown option is not set to :brutal_kill. If it is set to :brutal_kill, terminate/2 callback in the genserver worker will not be run. Read more here. You should probably set the shutdown option to a timeout that suits your application, eg: shutdown: 10_000
In your genserver, in the init/1 call, set the trap exits flag to true:
or using pure elixir
Then you can declare a terminate callback function in your genserver worker:
def terminate(reason, state) do
Asked in February 2016Viewed 2,178 timesVoted 11Answered 3 times