<commit_before>%% Copyright (c) 2015, SiftLogic LLC
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
%% copyright notice and this permission notice appear in all copies.
%%
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-module(erldns_storage).

-behaviour(gen_server).

%% inter-module API
-export([start_link/0]).

%% API
-export([create/1,
         insert/2,
         delete_table/1,
         delete/2,
         backup_table/1,
         backup_tables/0,
         select/2,
         select/3,
         foldl/3,
         empty_table/1,
         list_table/1,
         load_zones/0,
         load_zones/1]).

%% gen_server callbacks
-export([init/1,
         handle_call/3,
         handle_cast/2,
         handle_info/2,
         terminate/2,
         code_change/3]).


-record(state, {}).

-define(POLL_WAIT_HOURS, 1).
-define(FILENAME, "zones.json").

%% Gen Server Callbacks
start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

%% @doc Inits the module, and sends a "timeout" to handle_info to start the poller for table backup
init([]) ->
    %%This call to handle_info starts the timer to backup tables in the given interval.
    {ok, #state{}, 0}.

handle_call(_Request, _From, State) ->
    {reply, ok, State, 0}.

handle_cast(_Msg, State) ->
    {noreply, State, 0}.

%% @doc Backups the tables in the given period
handle_info(timeout, State) ->
    Before = now(),
    {error, not_implemented} = backup_tables(),
    TimeSpentMs = timer:now_diff(now(), Before) div 1000,
    {noreply, State, max((?POLL_WAIT_HOURS * 60000) - TimeSpentMs, 0)};
handle_info(_Info, State) ->
    {noreply, State, 0}.

terminate(_Reason, _State) ->
    ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

<commit_msg>Switch from `erlang:now/0` to `erlang:timestamp/0`<commit_after>%% Copyright (c) 2015, SiftLogic LLC
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
%% copyright notice and this permission notice appear in all copies.
%%
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-module(erldns_storage).

-behaviour(gen_server).

%% inter-module API
-export([start_link/0]).

%% API
-export([create/1,
         insert/2,
         delete_table/1,
         delete/2,
         backup_table/1,
         backup_tables/0,
         select/2,
         select/3,
         foldl/3,
         empty_table/1,
         list_table/1,
         load_zones/0,
         load_zones/1]).

%% gen_server callbacks
-export([init/1,
         handle_call/3,
         handle_cast/2,
         handle_info/2,
         terminate/2,
         code_change/3]).


-record(state, {}).

-define(POLL_WAIT_HOURS, 1).
-define(FILENAME, "zones.json").

%% Gen Server Callbacks
start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

%% @doc Inits the module, and sends a "timeout" to handle_info to start the poller for table backup
init([]) ->
    %%This call to handle_info starts the timer to backup tables in the given interval.
    {ok, #state{}, 0}.

handle_call(_Request, _From, State) ->
    {reply, ok, State, 0}.

handle_cast(_Msg, State) ->
    {noreply, State, 0}.

%% @doc Backups the tables in the given period
handle_info(timeout, State) ->
    Before = erlang:timestamp(),
    {error, not_implemented} = backup_tables(),
    TimeSpentMs = timer:now_diff(erlang:timestamp(), Before) div 1000,
    {noreply, State, max((?POLL_WAIT_HOURS * 60000) - TimeSpentMs, 0)};
handle_info(_Info, State) ->
    {noreply, State, 0}.

terminate(_Reason, _State) ->
    ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.


{'fraction_non_alphanumeric': 0.11840136781363539, 'fraction_numerical': 0.01709767044240222, 'mean_word_length': 3.212421242124212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1269993', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1445, 'n_words': 488}