mirror of
https://github.com/valitydev/machinery-erlang.git
synced 2024-11-06 00:35:19 +00:00
Simplify machinery_mg_backend:new/2 usage (#3)
This commit is contained in:
parent
fa6ea4cd01
commit
4b582b951e
@ -62,17 +62,11 @@ get_backend_config() ->
|
|||||||
%% client
|
%% client
|
||||||
-spec get_backend(opts()) ->
|
-spec get_backend(opts()) ->
|
||||||
machinery_mg_backend:backend().
|
machinery_mg_backend:backend().
|
||||||
get_backend(Opts) ->
|
get_backend(#{woody_ctx := WoodyCtx}) ->
|
||||||
machinery_mg_backend:new(get_backend_opts(Opts)).
|
machinery_mg_backend:new(WoodyCtx, #{
|
||||||
|
|
||||||
-spec get_backend_opts(opts()) ->
|
|
||||||
machinery_mg_backend:backend_opts().
|
|
||||||
get_backend_opts(#{woody_ctx := WoodyCtx}) ->
|
|
||||||
#{
|
|
||||||
woody_ctx => WoodyCtx,
|
|
||||||
client => get_woody_client(),
|
client => get_woody_client(),
|
||||||
schema => config(schema)
|
schema => config(schema)
|
||||||
}.
|
}).
|
||||||
|
|
||||||
-spec get_woody_client() ->
|
-spec get_woody_client() ->
|
||||||
machinery_mg_client:woody_client().
|
machinery_mg_client:woody_client().
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
backend_config := backend_config()
|
backend_config := backend_config()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
|
||||||
-type handler(A) :: {logic_handler(A), handler_config()}. %% handler server spec
|
-type handler(A) :: {logic_handler(A), handler_config()}. %% handler server spec
|
||||||
|
|
||||||
-type handler_opts() :: machinery:handler_opts(#{
|
-type handler_opts() :: machinery:handler_opts(#{
|
||||||
@ -51,6 +50,11 @@
|
|||||||
|
|
||||||
-type backend() :: {?MODULE, backend_opts()}.
|
-type backend() :: {?MODULE, backend_opts()}.
|
||||||
|
|
||||||
|
-type backend_opts_static() :: #{
|
||||||
|
client := machinery_mg_client:woody_client(),
|
||||||
|
?BACKEND_CORE_OPTS
|
||||||
|
}.
|
||||||
|
|
||||||
-export_type([backend_config/0]).
|
-export_type([backend_config/0]).
|
||||||
-export_type([handler_config/0]).
|
-export_type([handler_config/0]).
|
||||||
-export_type([logic_handler/1]).
|
-export_type([logic_handler/1]).
|
||||||
@ -62,7 +66,7 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([get_routes/2]).
|
-export([get_routes/2]).
|
||||||
-export([get_handler/2]).
|
-export([get_handler/2]).
|
||||||
-export([new/1]).
|
-export([new/2]).
|
||||||
|
|
||||||
%% Machinery backend
|
%% Machinery backend
|
||||||
-behaviour(machinery_backend).
|
-behaviour(machinery_backend).
|
||||||
@ -91,10 +95,10 @@ get_handler({LogicHandler, #{path := Path, backend_config := Config}}, _) ->
|
|||||||
{?MODULE, get_backend_handler_opts(LogicHandler, Config)}
|
{?MODULE, get_backend_handler_opts(LogicHandler, Config)}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec new(backend_opts()) ->
|
-spec new(woody_context:ctx(), backend_opts_static()) ->
|
||||||
backend().
|
backend().
|
||||||
new(Opts = #{woody_ctx := _, client := _, schema := _}) ->
|
new(WoodyCtx, Opts = #{client := _, schema := _}) ->
|
||||||
{?MODULE, Opts}.
|
{?MODULE, Opts#{woody_ctx => WoodyCtx}}.
|
||||||
|
|
||||||
%% Machinery backend
|
%% Machinery backend
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user