mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-07 21:44:36 +08:00
Handle review comments
This commit is contained in:
parent
5e03403bda
commit
16c51b505c
6 changed files with 33 additions and 22 deletions
|
@ -11,10 +11,10 @@ defmodule LiveBook.Application do
|
|||
LiveBookWeb.Telemetry,
|
||||
# Start the PubSub system
|
||||
{Phoenix.PubSub, name: LiveBook.PubSub},
|
||||
# Start the Endpoint (http/https)
|
||||
LiveBookWeb.Endpoint,
|
||||
# Start the supervisor dynamically managing sessions
|
||||
LiveBook.SessionSupervisor
|
||||
LiveBook.SessionSupervisor,
|
||||
# Start the Endpoint (http/https)
|
||||
LiveBookWeb.Endpoint
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
defmodule LiveBook.Session do
|
||||
@moduledoc """
|
||||
Server corresponding to a single notebook session.
|
||||
@moduledoc false
|
||||
|
||||
The process keeps the current notebook state and serves
|
||||
as a source of truth that multiple clients talk to.
|
||||
Receives update requests from the clients and notifies
|
||||
them of any changes applied to the notebook.
|
||||
"""
|
||||
# Server corresponding to a single notebook session.
|
||||
#
|
||||
# The process keeps the current notebook state and serves
|
||||
# as a source of truth that multiple clients talk to.
|
||||
# Receives update requests from the clients and notifies
|
||||
# them of any changes applied to the notebook.
|
||||
|
||||
use GenServer, restart: :temporary
|
||||
|
||||
@typedoc """
|
||||
A UUID assigned to every running session process.
|
||||
An id assigned to every running session process.
|
||||
"""
|
||||
@type session_id :: String.t()
|
||||
@type session_id :: LiveBook.Utils.id()
|
||||
|
||||
## API
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
defmodule LiveBook.SessionSupervisor do
|
||||
@moduledoc """
|
||||
Supervisor responsible for managing running notebook sessions.
|
||||
@moduledoc false
|
||||
|
||||
Allows for creating new session processes on demand
|
||||
and managing them using UUIDs.
|
||||
"""
|
||||
# Supervisor responsible for managing running notebook sessions.
|
||||
#
|
||||
# Allows for creating new session processes on demand
|
||||
# and managing them using random ids.
|
||||
|
||||
use DynamicSupervisor
|
||||
|
||||
alias LiveBook.Session
|
||||
alias LiveBook.{Session, Utils}
|
||||
|
||||
@name __MODULE__
|
||||
|
||||
|
@ -28,7 +28,7 @@ defmodule LiveBook.SessionSupervisor do
|
|||
"""
|
||||
@spec create_session() :: {:ok, Session.session_id()} | {:error, any()}
|
||||
def create_session() do
|
||||
id = UUID.uuid4()
|
||||
id = Utils.random_id()
|
||||
|
||||
case DynamicSupervisor.start_child(@name, {Session, id}) do
|
||||
{:ok, _} ->
|
||||
|
|
13
lib/live_book/utils.ex
Normal file
13
lib/live_book/utils.ex
Normal file
|
@ -0,0 +1,13 @@
|
|||
defmodule LiveBook.Utils do
|
||||
@moduledoc false
|
||||
|
||||
@type id :: binary()
|
||||
|
||||
@doc """
|
||||
Generates a random binary id.
|
||||
"""
|
||||
@spec random_id() :: binary()
|
||||
def random_id() do
|
||||
:crypto.strong_rand_bytes(20) |> Base.encode32(case: :lower)
|
||||
end
|
||||
end
|
3
mix.exs
3
mix.exs
|
@ -41,8 +41,7 @@ defmodule LiveBook.MixProject do
|
|||
{:telemetry_metrics, "~> 0.4"},
|
||||
{:telemetry_poller, "~> 0.4"},
|
||||
{:jason, "~> 1.0"},
|
||||
{:plug_cowboy, "~> 2.0"},
|
||||
{:elixir_uuid, "~> 1.2"}
|
||||
{:plug_cowboy, "~> 2.0"}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
1
mix.lock
1
mix.lock
|
@ -2,7 +2,6 @@
|
|||
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
|
||||
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
|
||||
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
|
||||
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
|
||||
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||
"floki": {:hex, :floki, "0.29.0", "b1710d8c93a2f860dc2d7adc390dd808dc2fb8f78ee562304457b75f4c640881", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "008585ce64b9f74c07d32958ec9866f4b8a124bf4da1e2941b28e41384edaaad"},
|
||||
"html_entities": {:hex, :html_entities, "0.5.1", "1c9715058b42c35a2ab65edc5b36d0ea66dd083767bef6e3edb57870ef556549", [:mix], [], "hexpm", "30efab070904eb897ff05cd52fa61c1025d7f8ef3a9ca250bc4e6513d16c32de"},
|
||||
|
|
Loading…
Add table
Reference in a new issue