<commit_before>%% @author Northscale <<EMAIL>>
%% @copyright 2009 NorthScale, Inc.
%%
%% 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.
%%
%% Run a set of processes per bucket

-module(ns_bucket_sup).

-behaviour(supervisor).

-include("ns_common.hrl").

-export([start_link/0]).

-export([init/1]).


%% API
start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).


%% supervisor callbacks

init([]) ->
    ns_pubsub:subscribe(
      ns_config_events,
      fun (Event, State) ->
              case Event of
                  {buckets, L} ->
                      Node = node(),
                      Buckets =
                          [B || {B, C} <- proplists:get_value(configs, L),
                                lists:member(Node, proplists:get_value(
                                                     servers, C, []))],
                      work_queue:submit_work(ns_bucket_worker,
                                             fun () ->
                                                     update_childs(Buckets)
                                             end);
                  _ -> ok
              end,
              State
      end, undefined),
    {ok, {{one_for_one, 3, 10},
          lists:flatmap(fun child_specs/1, ns_bucket:get_bucket_names())}}.

%% Internal functions

%% @private
%% @doc The child specs for each bucket.<commit_msg>really dont start ns_bucket_sup childs on not added nodes.MB-3488<commit_after>%% @author Northscale <<EMAIL>>
%% @copyright 2009 NorthScale, Inc.
%%
%% 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.
%%
%% Run a set of processes per bucket

-module(ns_bucket_sup).

-behaviour(supervisor).

-include("ns_common.hrl").

-export([start_link/0]).

-export([init/1]).


%% API
start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).


%% supervisor callbacks

init([]) ->
    ns_pubsub:subscribe(
      ns_config_events,
      fun (Event, State) ->
              case Event of
                  {buckets, L} ->
                      Buckets = get_this_node_bucket_names(proplists:get_value(configs, L, [])),
                      work_queue:submit_work(ns_bucket_worker,
                                             fun () ->
                                                     update_childs(Buckets)
                                             end);
                  _ -> ok
              end,
              State
      end, undefined),
    {ok, {{one_for_one, 3, 10},
          lists:flatmap(fun child_specs/1,
                        get_this_node_bucket_names(ns_bucket:get_buckets()))}}.

get_this_node_bucket_names(BucketsConfigs) ->
    Node = node(),
    [B || {B, C} <- BucketsConfigs,
          lists:member(Node, proplists:get_value(servers, C, []))].

%% Internal functions

%% @private
%% @doc The child specs for each bucket.
{'fraction_non_alphanumeric': 0.11388455538221529, 'fraction_numerical': 0.008320332813312533, 'mean_word_length': 1.9961059190031152, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3671833', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1014, 'n_words': 316}