Skip to content

Instantly share code, notes, and snippets.

@Laymer
Created October 21, 2018 12:14
Show Gist options
  • Save Laymer/1a182633081aec7e4d06650492cd7ba8 to your computer and use it in GitHub Desktop.
Save Laymer/1a182633081aec7e4d06650492cd7ba8 to your computer and use it in GitHub Desktop.
%%%-------------------------------------------------------------------
%% @author Igor Kopestenski <i.kopest@gmail.com>
%% [https://github.com/Laymer/]
%% @doc This is a <em>supervisor</em> template module.
%% @end
%%%-------------------------------------------------------------------
-module(supervisor_skeleton).
-behaviour(supervisor).
-include("header.hrl").
%% Supervisor API
-export([start_link/0
, start_child_supervisor/1
, start_child_worker/1]).
%% Supervisor Callbacks
-export([init/1]).
%%====================================================================
%% Macros
%%====================================================================
-define(SERVER, ?MODULE).
%%====================================================================
%% API
%%====================================================================
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
start_child_supervisor(Args) ->
ChildSpecs = #{id => child,
start => {child_sup, start_link, Args},
restart => permanent,
type => supervisor,
shutdown => 5000,
modules => [child_sup]},
supervisor:start_child(?SERVER, ChildSpecs).
start_child_worker(Args) ->
ChildSpecs = #{id => child,
start => {child_worker, start_link, Args},
restart => permanent,
type => worker,
shutdown => 5000,
modules => [child_worker]},
supervisor:start_child(?SERVER, ChildSpecs).
%%====================================================================
%% Callbacks
%%====================================================================
init([]) ->
MaxRestart = 6,
MaxTime = 3000,
{ok, {{one_for_one, MaxRestart, MaxTime}, []}}.
%%====================================================================
%% Internal functions
%%====================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment