diff --git a/apps/hellgate/src/hg_invoice.erl b/apps/hellgate/src/hg_invoice.erl index 2e88c569..e685f02b 100644 --- a/apps/hellgate/src/hg_invoice.erl +++ b/apps/hellgate/src/hg_invoice.erl @@ -37,6 +37,7 @@ %% Public interface -export([get/1]). +-export([get/2]). -export([get_payment/2]). -export([get_payment_opts/1]). -export([create/6]). @@ -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 -> diff --git a/apps/hellgate/src/hg_invoice_handler.erl b/apps/hellgate/src/hg_invoice_handler.erl index d4bff72d..a2c7abfe 100644 --- a/apps/hellgate/src/hg_invoice_handler.erl +++ b/apps/hellgate/src/hg_invoice_handler.erl @@ -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, @@ -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) -> @@ -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} -> diff --git a/apps/hellgate/test/hg_ct_helper.erl b/apps/hellgate/test/hg_ct_helper.erl index ae1f45f7..ebf51ad0 100644 --- a/apps/hellgate/test/hg_ct_helper.erl +++ b/apps/hellgate/test/hg_ct_helper.erl @@ -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, @@ -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 => #{ diff --git a/apps/prg_machine/src/prg_machine.erl b/apps/prg_machine/src/prg_machine.erl index ac960fb8..261fddc2 100644 --- a/apps/prg_machine/src/prg_machine.erl +++ b/apps/prg_machine/src/prg_machine.erl @@ -55,6 +55,10 @@ handling_timeout := timeout() }. +-type request_options() :: #{ + use_cache => boolean() +}. + -export_type([ namespace/0, id/0, @@ -73,7 +77,8 @@ repair_error/0, signal/0, result/0, - process_options/0 + process_options/0, + request_options/0 ]). %% Domain behaviour @@ -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]). @@ -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)}; @@ -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)}; @@ -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() -> diff --git a/compose.yaml b/compose.yaml index f8842668..09c8af63 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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" diff --git a/rebar.config b/rebar.config index e8f4c7ef..eda67919 100644 --- a/rebar.config +++ b/rebar.config @@ -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"}}}, diff --git a/rebar.lock b/rebar.lock index 5f6f7417..e35a8fe9 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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}, diff --git a/test/postgres/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh b/test/postgres/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh index d9950cde..02e7ab10 100755 --- a/test/postgres/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh +++ b/test/postgres/docker-entrypoint-initdb.d/create-multiple-postgresql-databases.sh @@ -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