Packages

A distributed Id generator

Current section

Files

Jump to
erlflake src erlflake_sup.erl
Raw

src/erlflake_sup.erl

%%%---------------------------------------------------------------------------
%%% Copyright (C) 2021, Fix Solution All Rights Reserved
%%% Unauthorized copy of this file is through any medium strictly not allowed.
%%%
%%% Authors : Alpha Shaw <shawalpha5@gmail.com>
%%% Created : 20 Apr 2021 by <shawalpha5@gmail.com>
%%% 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(erlflake_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 => one_for_one,
intensity => 1000,
period => 3600},
Workers =
#{id => worker,
start => {worker, start_link, []},
restart => transient,
shutdown => 10000,
type => worker,
modules => [worker]},
TsMng =
#{id => timestamp,
start => {timestamp, start_link, []},
restart => transient,
shutdown => 10000,
type => worker,
modules => [timestamp]},
GenSup =
#{id => generator_sup,
start => {generator_sup, start_link, []},
restart => permanent,
type => supervisor,
modules => [generator_sup]},
{ok, {SupFlags, [Workers, TsMng, GenSup]}}.