[erlang-patches] allow use of proplists in supervisor start specs

Richard Carlsson carlsson.richard@REDACTED
Tue Jan 3 22:11:47 CET 2012


The formats of the supervisor flags (the 3-tuple {one_for_one, Restarts, 
Time}) and the child specifications (6-tuples {name, etc., etc.}) are 
annoyingly hard both to read and write. This patch makes it possible to 
pass lists of options instead, and sets useful defaults for most fields. 
This also opens for the possibility to add more flags both to 
supervisors and children in the future.

   git fetch git://github.com/richcarl/otp.git proplist-child-spec

For example:

   init()
      SupFlags = [{period,10}],
      Child = [{name, foo}, {start, {M,F,A}}]
      {ok, {SupFlags, [Child]}}.

This gets you a one-for-one supervisor with a particular restart time 
period, and a single child with default behaviour. The name and start 
options are required.

The supervisor flag defaults are:

     strategy = one_for_one
     intensity = 10
     period = 30

I.e., one-for-one supervision and at most 10 restarts in the last 30 
seconds. This restart frequency seems like a useful default; let me know 
if you think some other numbers would be significantly better.

The child spec defaults are:
     restart_type = permanent
     shutdown = 2000
     child_type = worker
     modules = [M], where M is the module in the start MFA

Finally, there is a new function supervisor:get_childspec(Sup, Child) 
which can be used to get the full child specification (as a list) needed 
to restart the same child or another child like it.

Note that the documentation has not been updated as part of this patch.

   /Richard



More information about the erlang-patches mailing list