-
Notifications
You must be signed in to change notification settings - Fork 116
Use process labels #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Use process labels #330
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f6d0916
Show labels in error messages when possible
nathanl 282e6ea
Label DbConnection's own processes
nathanl 6ab5764
Update lib/db_connection/util.ex
nathanl 0ccc89d
Update lib/db_connection/util.ex
nathanl 7ba1b19
Update lib/db_connection/util.ex
nathanl 1fff5b5
Update lib/db_connection/util.ex
josevalim 4646cb1
Update lib/db_connection/util.ex
josevalim 7a9bad8
Format
nathanl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule DBConnection.Util do | ||
@moduledoc false | ||
|
||
@doc """ | ||
Inspect a pid, including the process label if possible. | ||
""" | ||
def inspect_pid(pid) do | ||
with :undefined <- get_label(pid), | ||
:undefined <- get_name(pid) do | ||
inspect(pid) | ||
else | ||
label_or_name -> "#{inspect(pid)} (#{inspect(label_or_name)})" | ||
end | ||
end | ||
|
||
defp get_name(pid) do | ||
try do | ||
Process.info(pid, :registered_name) | ||
rescue | ||
_ -> :undefined | ||
else | ||
{:registered_name, name} when is_atom(name) -> name | ||
_ -> :undefined | ||
end | ||
end | ||
|
||
@doc """ | ||
Set a process label if `Process.set_label/1` is available. | ||
""" | ||
def set_label(label) do | ||
if function_exported?(:proc_lib, :set_label, 1) do | ||
:proc_lib.set_label(label) | ||
else | ||
:ok | ||
end | ||
end | ||
|
||
# Get a process label if `:proc_lib.get_label/1` is available. | ||
defp get_label(pid) do | ||
if function_exported?(:proc_lib, :get_label, 1) do | ||
# Avoid a compiler warning if the function isn't | ||
# defined in your version of Erlang/OTP | ||
apply(:proc_lib, :get_label, [pid]) | ||
else | ||
# mimic return value of | ||
# `:proc_lib.get_label/1` when none is set. | ||
# Don't resort to using `Process.info(pid, :dictionary)`, | ||
# as this is not efficient. | ||
:undefined | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.