Log the reason a runtime node goes down (#1368)

Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
José Valim 2022-08-29 11:12:25 +02:00 committed by GitHub
parent aca9c18086
commit 895373e08b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 14 deletions

View file

@ -182,7 +182,6 @@ defmodule Livebook.Session do
* `{:hydrate_bin_entries, entries}`
* `{:operation, operation}`
* `{:error, error}`
* `{:info, info}`
"""
@spec subscribe(id()) :: :ok | {:error, term()}
@ -967,8 +966,11 @@ defmodule Livebook.Session do
end
@impl true
def handle_info({:DOWN, ref, :process, _, _}, %{runtime_monitor_ref: ref} = state) do
broadcast_info(state.session_id, "runtime node terminated unexpectedly")
def handle_info({:DOWN, ref, :process, _, reason}, %{runtime_monitor_ref: ref} = state) do
broadcast_error(
state.session_id,
"runtime node terminated unexpectedly - #{Exception.format_exit(reason)}"
)
{:noreply,
%{state | runtime_monitor_ref: nil}
@ -1511,10 +1513,6 @@ defmodule Livebook.Session do
broadcast_message(session_id, {:error, error})
end
defp broadcast_info(session_id, info) do
broadcast_message(session_id, {:info, info})
end
defp broadcast_message(session_id, message) do
Phoenix.PubSub.broadcast(Livebook.PubSub, "sessions:#{session_id}", message)
end

View file

@ -1106,12 +1106,6 @@ defmodule LivebookWeb.SessionLive do
{:noreply, put_flash(socket, :error, message)}
end
def handle_info({:info, info}, socket) do
message = info |> to_string() |> upcase_first()
{:noreply, put_flash(socket, :info, message)}
end
def handle_info({:hydrate_bin_entries, hydrated_entries}, socket) do
hydrated_entries_map = Map.new(hydrated_entries, fn entry -> {entry.cell.id, entry} end)

View file

@ -513,7 +513,7 @@ defmodule Livebook.SessionTest do
assert_receive {:operation, {:set_runtime, _, runtime}}
refute Runtime.connected?(runtime)
assert_receive {:info, "runtime node terminated unexpectedly"}
assert_receive {:error, "runtime node terminated unexpectedly - no connection"}
end
test "on user change sends an update operation subscribers", %{session: session} do