mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +01:00
More ejabberd_hooks refactor
This commit is contained in:
parent
fd91ee5169
commit
a339df2d6a
@ -304,9 +304,14 @@ code_change(_OldVsn, State, _Extra) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
-spec run1([local_hook()|distributed_hook()], atom(), list()) -> ok.
|
||||||
|
|
||||||
run1([], _Hook, _Args) ->
|
run1([], _Hook, _Args) ->
|
||||||
ok;
|
ok;
|
||||||
|
%% Run distributed hook on target node.
|
||||||
|
%% It is not attempted again in case of failure. Next hook will be executed
|
||||||
run1([{_Seq, Node, Module, Function} | Ls], Hook, Args) ->
|
run1([{_Seq, Node, Module, Function} | Ls], Hook, Args) ->
|
||||||
|
%% MR: Should we have a safe rpc, like we have a safe apply or is bad_rpc enough ?
|
||||||
case rpc:call(Node, Module, Function, Args, ?TIMEOUT_DISTRIBUTED_HOOK) of
|
case rpc:call(Node, Module, Function, Args, ?TIMEOUT_DISTRIBUTED_HOOK) of
|
||||||
timeout ->
|
timeout ->
|
||||||
?ERROR_MSG("Timeout on RPC to ~p~nrunning hook: ~p",
|
?ERROR_MSG("Timeout on RPC to ~p~nrunning hook: ~p",
|
||||||
@ -326,15 +331,10 @@ run1([{_Seq, Node, Module, Function} | Ls], Hook, Args) ->
|
|||||||
run1(Ls, Hook, Args)
|
run1(Ls, Hook, Args)
|
||||||
end;
|
end;
|
||||||
run1([{_Seq, Module, Function} | Ls], Hook, Args) ->
|
run1([{_Seq, Module, Function} | Ls], Hook, Args) ->
|
||||||
Res = if is_function(Function) ->
|
Res = safe_apply(Module, Function, Args),
|
||||||
catch apply(Function, Args);
|
|
||||||
true ->
|
|
||||||
catch apply(Module, Function, Args)
|
|
||||||
end,
|
|
||||||
case Res of
|
case Res of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nrunning hook: ~p",
|
?ERROR_MSG("~p~nrunning hook: ~p", [Reason, {Hook, Args}]),
|
||||||
[Reason, {Hook, Args}]),
|
|
||||||
run1(Ls, Hook, Args);
|
run1(Ls, Hook, Args);
|
||||||
stop ->
|
stop ->
|
||||||
ok;
|
ok;
|
||||||
@ -367,15 +367,10 @@ run_fold1([{_Seq, Node, Module, Function} | Ls], Hook, Val, Args) ->
|
|||||||
run_fold1(Ls, Hook, NewVal, Args)
|
run_fold1(Ls, Hook, NewVal, Args)
|
||||||
end;
|
end;
|
||||||
run_fold1([{_Seq, Module, Function} | Ls], Hook, Val, Args) ->
|
run_fold1([{_Seq, Module, Function} | Ls], Hook, Val, Args) ->
|
||||||
Res = if is_function(Function) ->
|
Res = safe_apply(Module, Function, [Val | Args]),
|
||||||
catch apply(Function, [Val | Args]);
|
|
||||||
true ->
|
|
||||||
catch apply(Module, Function, [Val | Args])
|
|
||||||
end,
|
|
||||||
case Res of
|
case Res of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nrunning hook: ~p",
|
?ERROR_MSG("~p~nrunning hook: ~p", [Reason, {Hook, Args}]),
|
||||||
[Reason, {Hook, Args}]),
|
|
||||||
run_fold1(Ls, Hook, Val, Args);
|
run_fold1(Ls, Hook, Val, Args);
|
||||||
stop ->
|
stop ->
|
||||||
stopped;
|
stopped;
|
||||||
@ -384,3 +379,10 @@ run_fold1([{_Seq, Module, Function} | Ls], Hook, Val, Args) ->
|
|||||||
NewVal ->
|
NewVal ->
|
||||||
run_fold1(Ls, Hook, NewVal, Args)
|
run_fold1(Ls, Hook, NewVal, Args)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
safe_apply(Module, Function, Args) ->
|
||||||
|
if is_function(Function) ->
|
||||||
|
catch apply(Function, Args);
|
||||||
|
true ->
|
||||||
|
catch apply(Module, Function, Args)
|
||||||
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user