mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
Enrich log events w/ machine ns / id + withdrawal meta (#46)
This commit is contained in:
parent
ff2510307a
commit
361122ff97
@ -553,7 +553,16 @@ is_finished(#{status := pending}) ->
|
||||
-spec process_transfer(withdrawal_state()) -> process_result().
|
||||
process_transfer(Withdrawal) ->
|
||||
Activity = deduce_activity(Withdrawal),
|
||||
do_process_transfer(Activity, Withdrawal).
|
||||
scoper:scope(
|
||||
withdrawal,
|
||||
#{activity => format_activity(Activity)},
|
||||
fun() -> do_process_transfer(Activity, Withdrawal) end
|
||||
).
|
||||
|
||||
format_activity(Activity) when is_atom(Activity) ->
|
||||
Activity;
|
||||
format_activity(Activity) ->
|
||||
genlib:format(Activity).
|
||||
|
||||
%%
|
||||
|
||||
|
@ -70,55 +70,60 @@ notify(NS, ID, Range, Args, Backend) ->
|
||||
-type handler_opts() :: _.
|
||||
|
||||
-spec init(args(_), machine(E, A), options(), handler_opts()) -> result(E, A).
|
||||
init(Args, Machine, Options, MachineryOptions) ->
|
||||
#{handler := Handler} = Options,
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal({init, Args}, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end.
|
||||
init(Args, Machine, Options = #{handler := Handler}, MachineryOptions) ->
|
||||
_ = scope(Machine, #{activity => init}, fun() ->
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal({init, Args}, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end
|
||||
end).
|
||||
|
||||
-spec process_timeout(machine(E, A), options(), handler_opts()) -> result(E, A).
|
||||
process_timeout(Machine, Options, MachineryOptions) ->
|
||||
#{handler := Handler} = Options,
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal(timeout, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end.
|
||||
process_timeout(Machine, Options = #{handler := Handler}, MachineryOptions) ->
|
||||
_ = scope(Machine, #{activity => timeout}, fun() ->
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal(timeout, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end
|
||||
end).
|
||||
|
||||
-spec process_call(args(_), machine(E, A), options(), handler_opts()) -> {response(_), result(E, A)}.
|
||||
process_call(Args, Machine, Options, MachineryOptions) ->
|
||||
#{handler := Handler} = Options,
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_call(Args, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end.
|
||||
process_call(Args, Machine, Options = #{handler := Handler}, MachineryOptions) ->
|
||||
_ = scope(Machine, #{activity => call}, fun() ->
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_call(Args, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end
|
||||
end).
|
||||
|
||||
-spec process_repair(args(_), machine(E, A), options(), handler_opts()) ->
|
||||
{ok, {response(_), result(E, A)}} | {error, machinery:error(_)}.
|
||||
process_repair(Args, Machine, Options, MachineryOptions) ->
|
||||
#{handler := Handler} = Options,
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_repair(Args, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end.
|
||||
process_repair(Args, Machine, Options = #{handler := Handler}, MachineryOptions) ->
|
||||
_ = scope(Machine, #{activity => repair}, fun() ->
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_repair(Args, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end
|
||||
end).
|
||||
|
||||
-spec process_notification(args(_), machine(E, A), options(), handler_opts()) -> result(E, A).
|
||||
process_notification(Args, Machine, Options, MachineryOptions) ->
|
||||
#{handler := Handler} = Options,
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal({notification, Args}, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end.
|
||||
process_notification(Args, Machine, Options = #{handler := Handler}, MachineryOptions) ->
|
||||
_ = scope(Machine, #{activity => notification}, fun() ->
|
||||
ok = ff_context:save(create_context(Options, MachineryOptions)),
|
||||
try
|
||||
machinery:dispatch_signal({notification, Args}, Machine, machinery_utils:get_handler(Handler), #{})
|
||||
after
|
||||
ff_context:cleanup()
|
||||
end
|
||||
end).
|
||||
|
||||
%% Internals
|
||||
|
||||
@ -138,3 +143,13 @@ set_backend_context(Backend) ->
|
||||
{Mod, Opts#{
|
||||
woody_ctx => ff_context:get_woody_context(ff_context:load())
|
||||
}}.
|
||||
|
||||
scope(Machine, Extra, Fun) ->
|
||||
scoper:scope(
|
||||
machine,
|
||||
Extra#{
|
||||
namespace => maps:get(namespace, Machine),
|
||||
id => maps:get(id, Machine)
|
||||
},
|
||||
Fun
|
||||
).
|
||||
|
Loading…
Reference in New Issue
Block a user