Link to cloud instance when system memory is low (#1122)

* Link to cloud instance when system memory is low

* Update wording and add link
This commit is contained in:
Jonatan Kłosko 2022-04-15 23:52:33 +02:00 committed by GitHub
parent ac5fd7e637
commit 87c27b5be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,9 @@ defmodule LivebookWeb.HomeLive do
file_info: %{exists: true, access: :read_write}, file_info: %{exists: true, access: :read_write},
sessions: sessions, sessions: sessions,
notebook_infos: notebook_infos, notebook_infos: notebook_infos,
page_title: "Livebook" page_title: "Livebook",
app_service_url: Livebook.Config.app_service_url(),
memory: Livebook.SystemResources.memory()
)} )}
end end
@ -39,6 +41,7 @@ defmodule LivebookWeb.HomeLive do
</SidebarHelpers.sidebar> </SidebarHelpers.sidebar>
<div class="grow px-6 py-8 overflow-y-auto"> <div class="grow px-6 py-8 overflow-y-auto">
<div class="max-w-screen-lg w-full mx-auto px-4 pb-8 space-y-4"> <div class="max-w-screen-lg w-full mx-auto px-4 pb-8 space-y-4">
<.memory_notification memory={@memory} app_service_url={@app_service_url} />
<div class="flex flex-col space-y-2 items-center pb-4 border-b border-gray-200 <div class="flex flex-col space-y-2 items-center pb-4 border-b border-gray-200
sm:flex-row sm:space-y-0 sm:justify-between"> sm:flex-row sm:space-y-0 sm:justify-between">
<div class="text-2xl text-gray-800 font-semibold"> <div class="text-2xl text-gray-800 font-semibold">
@ -104,7 +107,7 @@ defmodule LivebookWeb.HomeLive do
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="py-12" role="region" aria-label="running sessions"> <div id="running-sessions" class="py-12" role="region" aria-label="running sessions">
<.live_component module={LivebookWeb.HomeLive.SessionListComponent} <.live_component module={LivebookWeb.HomeLive.SessionListComponent}
id="session-list" id="session-list"
sessions={@sessions}/> sessions={@sessions}/>
@ -154,6 +157,23 @@ defmodule LivebookWeb.HomeLive do
end end
end end
defp memory_notification(assigns) do
~H"""
<%= if @app_service_url && @memory.free < 30_000_000 do %>
<div class="flex justify-between items-center border-b border-gray-200 pb-4 text-gray-700">
<span class="flex items-end">
<.remix_icon icon="alarm-warning-line" class="text-xl mr-2" />
<span>
Less than 30 MB of memory left, consider adding more resources to
<a class="font-semibold" href={@app_service_url} target="_blank">the instance</a>
or closing <a class="font-semibold" href="#running-sessions">running sessions</a>.
</span>
</span>
</div>
<% end %>
"""
end
@impl true @impl true
def handle_params(%{"session_id" => session_id}, _url, socket) do def handle_params(%{"session_id" => session_id}, _url, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id)) session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))