-module(ebb_work_supv). -behaviour(supervisor). %% API -export([start_link/1, start_work/4]). %% Supervisor callbacks -export([init/1]). -define(SERVER, ?MODULE). %%==================================================================== %% API functions %%==================================================================== %%-------------------------------------------------------------------- %% Function: start_link() -> {ok,Pid} | ignore | {error,Error} %% Description: Starts the supervisor %%-------------------------------------------------------------------- start_link(Args) -> supervisor:start_link({local, ?SERVER}, ?MODULE, Args). start_work(local, Func, Args, Receiver) -> Worker = {make_ref(), {ebb_worker, start_link, [Func, Args, Receiver]}, transient, brutal_kill, worker, [ebb_worker]}, supervisor:start_child(?SERVER, Worker); start_work(distributed, Func, Args, Receiver) -> Worker = {make_ref(), {ebb_worker, start_link, [distributed, Func, Args, Receiver]}, transient, brutal_kill, supervisor, [ebb_worker]}, supervisor:start_child(?SERVER, Worker). %%==================================================================== %% Supervisor callbacks %%==================================================================== %%-------------------------------------------------------------------- %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} | %% ignore | %% {error, Reason} %% Description: Whenever a supervisor is started using %% supervisor:start_link/[2,3], this function is called by the new process %% to find out about restart strategy, maximum restart frequency and child %% specifications. %%-------------------------------------------------------------------- init(Args) -> Manager = {ebb_work_manager, {ebb_work_manager, start_link, [Args]}, permanent, 2000, worker, [ebb_work_manager]}, {ok, {{one_for_one, 5, 5}, [Manager]}}. %%==================================================================== %% Internal functions %%====================================================================