%%%--------------------------------------------------------------------------- %%% Copyright (C) 2021, Fix Solution All Rights Reserved %%% Unauthorized copy of this file is through any medium strictly not allowed. %%% %%% Authors : Alpha Shaw %%% Created : 20 Apr 2021 by %%% Purpose : %%% %%% %%% Licensed under the Apache License, Version 2.0 (the "License"); %%% you may not use this file except in compliance with the License. %%% You may obtain a copy of the License at %%% %%% http://www.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%%--------------------------------------------------------------------------- -module(generator_sup). -behaviour(supervisor). -include_lib("erlflake.hrl"). -export([start_link/0]). -export([init/1]). -define(SERVER, ?MODULE). -define(GEN_TYPES, [0, 1]). start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). init([]) -> SupFlags = #{strategy => simple_one_for_one, intensity => 1000, period => 3600}, ChildSpecs = [ #{ id => generator, start => {generator, start_link, []}, restart => permanent, shutdown => 10000, type => worker, modules => [pulserl_conn] }], spawn( fun() -> timer:sleep(100), {ok, _Pid} = start_generator() end), {ok, {SupFlags, ChildSpecs}}. start_generator() -> case worker:reserve() of {ok, Worker} when is_integer(Worker) -> supervisor:start_child(?MODULE, [Worker]); Other -> {error, Other} end.