Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5c758dd
if nothing matches, don't fail
ginahagg Jan 12, 2022
d452d3e
added test, and fix return type for handle_info
ginahagg Jan 12, 2022
0ad79a3
filter the rb flights out
ginahagg Jan 12, 2022
2db32ba
add a test
ginahagg Jan 13, 2022
4210be2
add rtb_gateway_persist to children, will change name later
ginahagg Jan 13, 2022
0a22260
will move testing to gateway
ginahagg Feb 16, 2022
5b494e3
add specs
ginahagg Feb 16, 2022
d4d8662
Tested with gateway
ginahagg Feb 17, 2022
c12142a
Mask private info in test
ginahagg Feb 17, 2022
9954e97
Add another test for finding rb flights
ginahagg Feb 18, 2022
5a453ed
move bool_test inside test unit
ginahagg Feb 18, 2022
8b693f7
abstract terms
ginahagg Feb 19, 2022
41fbf28
fix boolean string to include key field
ginahagg Feb 19, 2022
da41f13
timing added
ginahagg Feb 22, 2022
9a43f0f
Add specs and add back missing func
ginahagg Feb 22, 2022
2916615
Persist under rig_persist in persistent_term
ginahagg Feb 22, 2022
6883809
Delete flights.term.no
ginahagg Feb 22, 2022
a010c4c
Delete flights.term
ginahagg Feb 22, 2022
1054486
Delete flights.bert.no
ginahagg Feb 22, 2022
525afc9
got rid of reformat
ginahagg Feb 23, 2022
9342950
take off reformat
ginahagg Feb 23, 2022
f7f1026
add extra last line
ginahagg Feb 23, 2022
1e69f5a
remove format from test erl files
ginahagg Feb 23, 2022
3c84de6
remove format from test rig_test files
ginahagg Feb 23, 2022
4bcf9bb
remove last diff with adding linespace
ginahagg Feb 23, 2022
bb2a95d
Merge pull request #1 from adgear/shortpipe
ginahagg Feb 23, 2022
9a7ffdc
add init and terminate logs
ginahagg Feb 28, 2022
6917abd
Only parse the new ones and purge old map and add the new
ginahagg Mar 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/rebar3
Binary file not shown.
22 changes: 12 additions & 10 deletions include/rig.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
-define(GET_ENV(Key, Default), application:get_env(?APP, Key, Default)).
-define(LOOKUP(Key, List, Default), rig_utils:lookup(Key, List, Default)).
-define(SERVER, rig_server).

%% ETS tables
-define(ETS_TABLE_INDEX, rig_index).

%% msgs
-define(MSG_RELOAD, reload).
-define(MSG_RELOAD_CONFIG, reload_config).

%% defaults
-define(DEFAULT_CLEANUP_DELAY, 500).
-define(DEFAULT_CONFIGS, []).
Expand All @@ -22,20 +19,25 @@

%% types
-type basedir() :: string().
-type config() :: {table(), file(), decoder(), options()}.
-type config() :: {table(), file(), decoder(), options()}.
-type decoder() :: fun((binary()) -> tuple()) | term | {module(), function()}.
-type file() :: string().
-type key() :: term().
-type option() :: {key_element, pos_integer()} | {subscribers, [pid()]}.
-type file() :: string().
-type key() :: term().
-type option() :: {key_element, pos_integer()} | {subscribers, [pid()]}.
-type options() :: [option()].
-type table() :: atom().
-type value() :: term().
-type table() :: atom().
-type value() :: term().

%% compatibility
-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).

-define( EXCEPTION( Class , Reason , Stacktrace ) , Class : Reason : Stacktrace ) .

-define(GET_STACK(Stacktrace), Stacktrace).

-else.

-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).

-endif.
63 changes: 63 additions & 0 deletions src/rig_persist.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 et
-module(rig_persist).

% http://erlang.org/doc/design_principles/gen_server_concepts.html
-behaviour(gen_server).

-include("rig.hrl").

-ifdef(EUNIT).

-include_lib("eunit/include/eunit.hrl").

-endif.

% API
-export([start_link/0]).
% Callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).

-record(state, {}).

-define(PERSIST_CRITERIA, application:get_env(?APP, persist_criteria, [])).

-spec start_link() -> {ok, pid()}.
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

% Callbacks
-spec init([]) -> {ok, term()}.
init(_Args) ->
error_logger : info_msg( "rig_persist reporting to work in"),
{ok, #state{}}.

-spec handle_call(term(), pid(), term()) -> {ok, term()}.
handle_call(_Request, _From, State) ->
{reply, ignored, State}.

-spec handle_cast(term(), term()) -> {ok, term()}.
handle_cast(_Msg, State) ->
{noreply, State}.

-spec handle_info(term(), term()) -> {ok, term()}.
handle_info({rig_index, update, Table}, State) ->
Now = erlang:system_time(millisecond),
{ok, Records} = rig:all(Table),
rig_persist_utils:to_persistent_term(Records),
Then = erlang:system_time(millisecond),
error_logger : info_msg( "rig_persist persisted in ~p millsecs" , [ Then - Now ] ),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.

-spec terminate(term(), term()) -> term().
terminate(Reason, _State) ->
error_logger : info_msg( "rig_persist terminating with Reason: ~p~n",[Reason]),
ok.

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

Loading