Skip to content

Commit

Permalink
Add rabbit_misc:process_info/2 that also works for remote PIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
gomoripeti committed Dec 9, 2024
1 parent c15ba8e commit 7b7708f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion deps/rabbit_common/src/rabbit_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
build_acyclic_graph/3]).
-export([const/1]).
-export([ntoa/1, ntoab/1]).
-export([is_process_alive/1]).
-export([is_process_alive/1,
process_info/2]).
-export([pget/2, pget/3, pupdate/3, pget_or_die/2, pmerge/3, pset/3, plmerge/2]).
-export([deep_pget/2, deep_pget/3]).
-export([format_message_queue/2]).
Expand Down Expand Up @@ -812,6 +813,23 @@ is_process_alive(Pid) ->
lists:member(Node, [node() | nodes(connected)]) andalso
rpc:call(Node, erlang, is_process_alive, [Pid]) =:= true.

%% Get process info of a prossibly remote process.
%% We try to avoid reconnecting to down nodes.
-spec process_info(pid(), ItemSpec) -> Result| undefined | {badrpc, term()}
when
ItemSpec :: atom() | list() | tuple(),
Result :: {atom() | tuple(), term()} | [{atom() | tuple(), term()}].
process_info(Pid, Items) when node(Pid) =:= node() ->
erlang:process_info(Pid, Items);
process_info(Pid, Items) ->
Node = node(Pid),
case lists:member(Node, [node() | nodes(connected)]) of
true ->
rpc:call(Node, erlang, process_info, [Pid, Items]);
_ ->
{badrcp, nodedown}
end.

-spec pget(term(), list() | map()) -> term().
pget(K, M) when is_map(M) ->
maps:get(K, M, undefined);
Expand Down

0 comments on commit 7b7708f

Please sign in to comment.