Skip to content

Instantly share code, notes, and snippets.

View jfcloutier's full-sized avatar

Jean-Francois Cloutier jfcloutier

View GitHub Profile
@jfcloutier
jfcloutier / fault_tolerant_event_manager.ex
Last active December 4, 2020 05:41
Fault-tolerant event managers in Elixir
# By default, GenEvent event handlers fail silently and are not automatically restarted. Not good.
# There's an easy enough way to correct this.
# You'll need to
# 1. define a supervised event manager as a GenServer,
# 2. register its GenEvent handlers with monitoring enabled
# 3. catch handler exits as "out of band" messages (handle_info)
# 4. stop the event manager when any handler crashes, relying on the supervisor to restart the event
# manager who will then restart all of its GenEvent handlers.
# This approach assumes that event handling is either stateless or can reset its state without issues.