<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2020 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% This module provides functions operating on #internal_service{}
%%% record that represents service that should work permanently
%%% (see internal_services_manager.erl). The record is stored
%%% in datastore as a part of #node_internal_services{} record.
%%% @end
%%%-------------------------------------------------------------------
-module(internal_service).
-author("<NAME>").

-include("modules/datastore/datastore_models.hrl").

%% API
-export([new/3, apply_start_fun/1, apply_start_fun/2,
    apply_takeover_fun/1, apply_stop_fun/2, apply_migrate_fun/1]).

% Record representing service that should work permanently
-record(internal_service, {
    module :: module(),
    start_function :: service_fun_name(),
    takeover_function :: service_fun_name(),
    migrate_function :: service_fun_name(),
    stop_function :: service_fun_name(),
    start_function_args :: service_fun_args(),
    takeover_function_args :: service_fun_args(),
    migrate_function_args :: service_fun_args(),
    stop_function_args :: service_fun_args(),
    hashing_key :: internal_services_manager:hashing_base()
}).

-type service() :: #internal_service{}.
-type service_name() :: binary().
-type service_fun_name() :: atom().
-type service_fun_args() :: list().
-type options() :: #{
    start_function := service_fun_name(),
    start_function_args := service_fun_args(),
    takeover_function => service_fun_name(),
    takeover_function_args => service_fun_args(),
    migrate_function => service_fun_name(),
    migrate_function_args => service_fun_args(),
    stop_function => service_fun_name(),
    stop_function_args => service_fun_args()
}.

-export_type([service_name/0, service_fun_name/0, service_fun_args/0, options/0]).

%%%===================================================================
%%% API
%%%===================================================================

-spec new(module(), internal_services_manager:hashing_base(), options()) -> service().
new(Module, HashingBase, ServiceDescription) ->
    Fun = maps:get(start_function, ServiceDescription),
    Args = maps:get(start_function_args, ServiceDescription),<commit_msg>VFS-6287 Fix dialyzer<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2020 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% This module provides functions operating on #internal_service{}
%%% record that represents service that should work permanently
%%% (see internal_services_manager.erl). The record is stored
%%% in datastore as a part of #node_internal_services{} record.
%%% @end
%%%-------------------------------------------------------------------
-module(internal_service).
-author("<NAME>").

-include("modules/datastore/datastore_models.hrl").

%% API
-export([new/3, apply_start_fun/1, apply_start_fun/2,
    apply_takeover_fun/1, apply_stop_fun/2, apply_migrate_fun/1]).

% Record representing service that should work permanently
-record(internal_service, {
    module :: module(),
    start_function :: service_fun_name(),
    takeover_function :: service_fun_name(),
    migrate_function :: service_fun_name(),
    stop_function :: service_fun_name(),
    start_function_args :: service_fun_args(),
    takeover_function_args :: service_fun_args(),
    migrate_function_args :: service_fun_args(),
    stop_function_args :: service_fun_args(),
    hashing_key :: internal_services_manager:hashing_base()
}).

-type service() :: #internal_service{}.
-type service_name() :: binary().
-type service_fun_name() :: atom().
-type service_fun_args() :: list().
-type options() :: #{
    start_function := service_fun_name(),
    start_function_args := service_fun_args(),
    takeover_function => service_fun_name(),
    takeover_function_args => service_fun_args(),
    migrate_function => service_fun_name(),
    migrate_function_args => service_fun_args(),
    stop_function => service_fun_name(),
    stop_function_args => service_fun_args()
}.

-export_type([service/0, service_name/0, service_fun_name/0, service_fun_args/0, options/0]).

%%%===================================================================
%%% API
%%%===================================================================

-spec new(module(), internal_services_manager:hashing_base(), options()) -> service().
new(Module, HashingBase, ServiceDescription) ->
    Fun = maps:get(start_function, ServiceDescription),
    Args = maps:get(start_function_args, ServiceDescription),
{'fraction_non_alphanumeric': 0.26019063070371123, 'fraction_numerical': 0.006692354491989455, 'mean_word_length': 3.688212927756654, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232348', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1350, 'n_words': 280}