Skip to content

Instantly share code, notes, and snippets.

@seven1240
Last active December 14, 2015 03:49
Show Gist options
  • Save seven1240/5023869 to your computer and use it in GitHub Desktop.
Save seven1240/5023869 to your computer and use it in GitHub Desktop.
-module(xcds_user_sup).
-behaviour(supervisor).
%% API
-export([start_link/0, start_users/0]).
%% Supervisor callbacks
-export([init/1]).
%% Helper macro for declaring children of supervisor
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
%% ===================================================================
%% API functions
%% ===================================================================
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%% ===================================================================
%% Supervisor callbacks
%% ===================================================================
init([]) ->
%% initing ets tables
timer:apply_after(2000, ?MODULE, start_users, []),
Child = ?CHILD(xcds_user, worker),
gen_event:add_handler(some_handler),
{ok, { {simple_one_for_one, 5, 10}, [Child]} }.
terminate() ->
gen_event:remove_handler(some_handler).
start_users() ->
?LOG(info, "start users .........~n", []),
{ok, _, Records} = m_user:all(),
[ supervisor:start_child(?MODULE, [element(1, Rec)]) || Rec <- Records].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment