Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion apps/hellgate/src/hg_invoice.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
%% Public interface

-export([get/1]).
-export([get/2]).
-export([get_payment/2]).
-export([get_payment_opts/1]).
-export([create/6]).
Expand Down Expand Up @@ -102,7 +103,11 @@

-spec get(prg_machine:id()) -> {ok, st()} | {error, prg_machine:get_error()}.
get(ID) ->
case prg_machine:get(?NS, ID) of
get(ID, #{}).

-spec get(prg_machine:id(), prg_machine:request_options()) -> {ok, st()} | {error, prg_machine:get_error()}.
get(ID, Opts) ->
case prg_machine:get(?NS, ID, #{direction => forward}, Opts) of
{ok, Machine} ->
{ok, prg_machine:collapse(?MODULE, Machine)};
Error ->
Expand Down
9 changes: 6 additions & 3 deletions apps/hellgate/src/hg_invoice_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ handle_function_('Create', {InvoiceParams}, _Opts) ->
MerchantTerms = hg_invoice_utils:compute_shop_terms(DomainRevision, Shop, VS),
ok = validate_invoice_params(InvoiceParams, Shop, MerchantTerms),
ok = ensure_started(InvoiceID, undefined, InvoiceParams, undefined, Mutations, DomainRevision),
get_invoice_state(get_state(InvoiceID));
get_invoice_state(get_state(InvoiceID, #{use_cache => false}));
handle_function_('CreateWithTemplate', {Params}, _Opts) ->
DomainRevision = hg_domain:head(),
InvoiceID = Params#payproc_InvoiceWithTemplateParams.id,
Expand All @@ -65,7 +65,7 @@ handle_function_('CreateWithTemplate', {Params}, _Opts) ->
MerchantTerms = hg_invoice_utils:compute_shop_terms(DomainRevision, Shop, VS),
ok = validate_invoice_params(InvoiceParams, Shop, MerchantTerms),
ok = ensure_started(InvoiceID, TplID, InvoiceParams, undefined, Mutations, DomainRevision),
get_invoice_state(get_state(InvoiceID));
get_invoice_state(get_state(InvoiceID, #{use_cache => false}));
handle_function_('CapturePaymentNew', Args, Opts) ->
handle_function_('CapturePayment', Args, Opts);
handle_function_('Get', {InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}}, _Opts) ->
Expand Down Expand Up @@ -223,7 +223,10 @@ set_invoicing_meta(InvoiceID, PaymentID) ->
%%

get_state(ID) ->
case hg_invoice:get(ID) of
get_state(ID, #{}).

get_state(ID, Opts) ->
case hg_invoice:get(ID, Opts) of
{ok, St} ->
St;
{error, notfound} ->
Expand Down
15 changes: 14 additions & 1 deletion apps/hellgate/test/hg_ct_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ start_app(epg_connector = AppName) ->
start_app(progressor = AppName) ->
{
start_app(AppName, [
{call_wait_timeout, 20},
%% Uncomment this when cache enabled on prod
%{post_init_hooks, [
% {prg_pg_cache, start, [#{default_db => {[invoice], "hellgate_cache"}}]}
%]},
{defaults, #{
storage => #{
client => prg_pg_backend,
Expand Down Expand Up @@ -327,6 +330,16 @@ start_app(progressor = AppName) ->
ns => invoice
}
},
storage => #{
client => prg_pg_backend,
options => #{
%% Uncomment this when cache enabled on prod
%cache => enabled,
pool => default_pool,
front_pool => default_front_pool,
scan_pool => default_scan_pool
}
},
worker_pool_size => 150
},
invoice_template => #{
Expand Down
21 changes: 16 additions & 5 deletions apps/prg_machine/src/prg_machine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
handling_timeout := timeout()
}.

-type request_options() :: #{
use_cache => boolean()
}.

-export_type([
namespace/0,
id/0,
Expand All @@ -73,7 +77,8 @@
repair_error/0,
signal/0,
result/0,
process_options/0
process_options/0,
request_options/0
]).

%% Domain behaviour
Expand Down Expand Up @@ -108,6 +113,7 @@
-export([repair/3]).
-export([get/2]).
-export([get/3]).
-export([get/4]).
-export([get_history/2]).
-export([get_history/4]).
-export([get_history/5]).
Expand Down Expand Up @@ -164,7 +170,7 @@ call(NS, ID, CallArgs) ->
-spec call(namespace(), id(), call(), event_id() | undefined, non_neg_integer() | undefined, forward | backward) ->
{ok, response()} | {error, notfound | failed | timeout | {unknown_namespace, namespace()} | term()}.
call(NS, ID, CallArgs, After, Limit, Direction) ->
Req = request(NS, ID, CallArgs, encode_range(After, Limit, Direction)),
Req = request(NS, ID, CallArgs, encode_range(After, Limit, Direction), #{}),
case progressor:call(Req) of
{ok, Response} ->
{ok, decode_term(Response)};
Expand Down Expand Up @@ -216,9 +222,13 @@ get(NS, ID) ->

-spec get(namespace(), id(), history_range()) -> {ok, machine()} | {error, get_error()}.
get(NS, ID, Range) ->
get(NS, ID, Range, #{}).

-spec get(namespace(), id(), history_range(), request_options()) -> {ok, machine()} | {error, get_error()}.
get(NS, ID, Range, Opts) ->
case prg_machine_registry:lookup(NS) of
{ok, Handler} ->
Req = request(NS, ID, undefined, Range),
Req = request(NS, ID, undefined, Range, Opts),
case progressor:get(Req) of
{ok, Process} ->
{ok, unmarshal_machine(Handler, NS, Process)};
Expand Down Expand Up @@ -471,13 +481,14 @@ initial_model(_Handler, _AuxState) ->

%% RPC / terms

request(NS, ID, Args, Range) ->
request(NS, ID, Args, Range, Opts) ->
genlib_map:compact(#{
ns => NS,
id => ID,
args => encode_term(Args),
context => encode_rpc_context(),
range => Range
range => Range,
options => Opts
}).

encode_rpc_context() ->
Expand Down
4 changes: 3 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ services:

db:
image: postgres:17
command: -c 'max_connections=1000'
command: >
-c max_connections=1000
-c wal_level=logical
environment:
POSTGRES_MULTIPLE_DATABASES: "hellgate,fistful,bender,dmt,party_management,shumway,liminator,customer_storage"
POSTGRES_PASSWORD: "postgres"
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{fault_detector_proto, {git, "https://github.com/valitydev/fault-detector-proto.git", {branch, "master"}}},
{limiter_proto, {git, "https://github.com/valitydev/limiter-proto.git", {tag, "v2.1.1"}}},
{herd, {git, "https://github.com/wgnet/herd.git", {tag, "1.3.4"}}},
{progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.27"}}},
{progressor, {git, "https://github.com/valitydev/progressor.git", {tag, "v1.0.28"}}},
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {tag, "v1.1.22"}}},
{fistful_proto, {git, "https://github.com/valitydev/fistful-proto.git", {branch, "master"}}},
{binbase_proto, {git, "https://github.com/valitydev/binbase-proto.git", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
0},
{<<"progressor">>,
{git,"https://github.com/valitydev/progressor.git",
{ref,"cb8ab2d88b4a49bf521647899eb4e72a24d53026"}},
{ref,"2435f86863a6ee3e6a1900cfcafaf15886e41112"}},
0},
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.11.0">>},0},
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.9">>},0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function create_user_and_database() {
\c $database;
CREATE USER $database;
ALTER USER $database WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD';
ALTER ROLE $database WITH REPLICATION;
GRANT ALL ON SCHEMA public TO $database;
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
EOSQL
Expand Down
Loading