Skip to content
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

Proposal: Allow consumers to follow "let it crash" methodology #631

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/nostrum/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ defmodule Nostrum.Consumer do

```elixir
def handle_info({:event, event}, state) do
Task.start_link(fn ->
__MODULE__.handle_event(event)
Task.start(fn ->
try do
__MODULE__.handle_event(event)
rescue
e ->
Logger.error("Error in event handler: \#{Exception.format_error(e, __STACKTRACE__)}")
end
end)

{:noreply, state}
Expand Down Expand Up @@ -408,6 +413,8 @@ defmodule Nostrum.Consumer do
quote location: :keep do
use GenServer

require Logger

@behaviour Nostrum.Consumer

@before_compile Nostrum.Consumer
Expand Down Expand Up @@ -436,8 +443,15 @@ defmodule Nostrum.Consumer do
@impl GenServer
def handle_info({:event, event}, state) do
{:ok, _pid} =
Task.start_link(fn ->
__MODULE__.handle_event(event)
Task.start(fn ->
try do
__MODULE__.handle_event(event)
rescue
e ->
Logger.error(
"Error in event handler: #{Exception.format_error(e, __STACKTRACE__)}"
)
end
end)

{:noreply, state}
Expand Down