-
-
Save seven1240/5023869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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