Make it possible to mark evaluating cell as stale upfront (#378)

* Make it possible to mark evaluating cell as stale upfront

* Show evaluation time on stale cells as well
This commit is contained in:
Jonatan Kłosko 2021-06-22 15:06:16 +02:00 committed by GitHub
parent 88d3c5e760
commit 6d0da78370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 7 deletions

View file

@ -606,7 +606,6 @@ defmodule Livebook.Session.Data do
defp finish_cell_evaluation(data_actions, cell, section, metadata) do defp finish_cell_evaluation(data_actions, cell, section, metadata) do
data_actions data_actions
|> set_cell_info!(cell.id, |> set_cell_info!(cell.id,
validity_status: :evaluated,
evaluation_status: :ready, evaluation_status: :ready,
evaluation_time_ms: metadata.evaluation_time_ms evaluation_time_ms: metadata.evaluation_time_ms
) )
@ -666,7 +665,15 @@ defmodule Livebook.Session.Data do
data_actions data_actions
|> set!(notebook: Notebook.update_cell(data.notebook, id, &%{&1 | outputs: []})) |> set!(notebook: Notebook.update_cell(data.notebook, id, &%{&1 | outputs: []}))
|> update_cell_info!(id, fn info -> |> update_cell_info!(id, fn info ->
%{info | evaluation_status: :evaluating, evaluation_digest: nil} %{
info
| evaluation_status: :evaluating,
evaluation_digest: nil,
# During evaluation notebook changes may invalidate the cell,
# so we mark it as up-to-date straight away and possibly mark
# it as stale during evaluation
validity_status: :evaluated
}
end) end)
|> set_section_info!(section.id, evaluating_cell_id: id, evaluation_queue: ids) |> set_section_info!(section.id, evaluating_cell_id: id, evaluation_queue: ids)
|> add_action({:start_evaluation, cell, section}) |> add_action({:start_evaluation, cell, section})

View file

@ -378,8 +378,11 @@ defmodule LivebookWeb.SessionLive.CellComponent do
) )
end end
defp render_cell_status(:stale, _, _) do defp render_cell_status(:stale, _, evaluation_time_ms) do
render_status_indicator("Stale", "bg-yellow-200", change_indicator: true) render_status_indicator("Stale", "bg-yellow-200",
change_indicator: true,
tooltip: evaluated_label(evaluation_time_ms)
)
end end
defp render_cell_status(:aborted, _, _) do defp render_cell_status(:aborted, _, _) do

View file

@ -1003,12 +1003,11 @@ defmodule Livebook.Session.DataTest do
}, []} = Data.apply_operation(data, operation) }, []} = Data.apply_operation(data, operation)
end end
test "marks the cell as evaluated" do test "marks the cell as ready" do
data = data =
data_after_operations!([ data_after_operations!([
{:insert_section, self(), 0, "s1"}, {:insert_section, self(), 0, "s1"},
{:insert_cell, self(), "s1", 0, :elixir, "c1"}, {:insert_cell, self(), "s1", 0, :elixir, "c1"},
{:insert_cell, self(), "s1", 1, :elixir, "c2"},
{:set_runtime, self(), NoopRuntime.new()}, {:set_runtime, self(), NoopRuntime.new()},
{:queue_cell_evaluation, self(), "c1"} {:queue_cell_evaluation, self(), "c1"}
]) ])
@ -1018,11 +1017,37 @@ defmodule Livebook.Session.DataTest do
assert {:ok, assert {:ok,
%{ %{
cell_infos: %{"c1" => %{validity_status: :evaluated, evaluation_status: :ready}}, cell_infos: %{"c1" => %{evaluation_status: :ready}},
section_infos: %{"s1" => %{evaluating_cell_id: nil, evaluation_queue: []}} section_infos: %{"s1" => %{evaluating_cell_id: nil, evaluation_queue: []}}
}, []} = Data.apply_operation(data, operation) }, []} = Data.apply_operation(data, operation)
end end
test "preserves validity status" do
data =
data_after_operations!([
{:insert_section, self(), 0, "s1"},
{:insert_cell, self(), "s1", 0, :elixir, "c1"},
{:insert_cell, self(), "s1", 1, :elixir, "c2"},
{:set_runtime, self(), NoopRuntime.new()},
# Evaluate the first cell
{:queue_cell_evaluation, self(), "c1"},
{:add_cell_evaluation_response, self(), "c1", {:ok, [1, 2, 3]},
%{evaluation_time_ms: 10}},
# Start evaluating the second cell
{:queue_cell_evaluation, self(), "c2"},
# Remove the first cell, marking the second as stale
{:delete_cell, self(), "c1"}
])
operation =
{:add_cell_evaluation_response, self(), "c2", {:ok, [1, 2, 3]}, %{evaluation_time_ms: 10}}
assert {:ok,
%{
cell_infos: %{"c2" => %{validity_status: :stale}}
}, []} = Data.apply_operation(data, operation)
end
test "marks next queued cell in this section as evaluating if there is one" do test "marks next queued cell in this section as evaluating if there is one" do
data = data =
data_after_operations!([ data_after_operations!([