Nanny for a GenEvent handler
This Application will create the Supervisor and manager under the same Parent Supervisor and every handler will be take care by GenServer and restart it when exit abnormally.
First, add EventNanny to your mix.exs dependencies:
def deps do
[{:event_nanny, "~> 0.1.1"}]
end
and run mix deps.get
. Now, list the :event_nanny
application as your application dependency:
def application do
[applications: [:event_nanny]]
end
Instead of adding a handler with GenEvent.add_handler(manager, handler, args)
or
GenEvent.add_mon_handler(manager, handler, args)
just use
EventNanny.add_mon_handler(handler, args)
You can named your manager
or add handle
when nanny started
config :event_nanny,
event_monitor: MyEventMonitor,
event_handler: [
{MyHandler, [arg1: 1, arg2: 2]},
{MyHandler, []}
]