Fix evaluation timer on page refresh (#732)

This commit is contained in:
Jonatan Kłosko 2021-12-03 14:23:50 +01:00 committed by GitHub
parent 0b6acb9d34
commit 4debf2c1fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

View file

@ -1,3 +1,5 @@
import { getAttributeOrThrow } from "../lib/attribute";
const UPDATE_INTERVAL_MS = 100;
/**
@ -6,8 +8,10 @@ const UPDATE_INTERVAL_MS = 100;
*/
const Timer = {
mounted() {
this.props = getProps(this);
this.state = {
start: Date.now(),
start: new Date(this.props.start),
interval: null,
};
@ -28,4 +32,10 @@ const Timer = {
},
};
function getProps(hook) {
return {
start: getAttributeOrThrow(hook.el, "data-start"),
};
}
export default Timer;

View file

@ -62,6 +62,7 @@ defmodule Livebook.Session.Data do
evaluation_digest: String.t() | nil,
evaluation_snapshot: snapshot() | nil,
evaluation_time_ms: integer() | nil,
evaluation_start: DateTime.t() | nil,
number_of_evaluations: non_neg_integer(),
bound_to_input_ids: MapSet.t(input_id()),
bound_input_readings: input_reading()
@ -980,7 +981,10 @@ defmodule Livebook.Session.Data do
evaluation_digest: nil,
evaluation_snapshot: info.snapshot,
bound_to_input_ids: MapSet.new(),
bound_input_readings: []
bound_input_readings: [],
# This is a rough estimate, the exact time is measured in the
# evaluator itself
evaluation_start: DateTime.utc_now()
}
end)
|> set_section_info!(section.id, evaluating_cell_id: id, evaluation_queue: ids)
@ -1292,6 +1296,7 @@ defmodule Livebook.Session.Data do
evaluation_status: :ready,
evaluation_digest: nil,
evaluation_time_ms: nil,
evaluation_start: nil,
number_of_evaluations: 0,
bound_to_input_ids: MapSet.new(),
bound_input_readings: [],

View file

@ -1322,6 +1322,7 @@ defmodule LivebookWeb.SessionLive do
validity_status: info.validity_status,
evaluation_status: info.evaluation_status,
evaluation_time_ms: info.evaluation_time_ms,
evaluation_start: info.evaluation_start,
number_of_evaluations: info.number_of_evaluations,
reevaluate_automatically: cell.reevaluate_automatically,
# Pass input values relevant to the given cell

View file

@ -254,7 +254,8 @@ defmodule LivebookWeb.SessionLive.CellComponent do
<span class="font-mono"
id={"cell-timer-#{@cell_view.id}-evaluation-#{@cell_view.number_of_evaluations}"}
phx-hook="Timer"
phx-update="ignore">
phx-update="ignore"
data-start={DateTime.to_iso8601(@cell_view.evaluation_start)}>
</span>
</.status_indicator>
"""