Use :version field from Livebook Teams event (#2633)

This commit is contained in:
Alexandre de Souza 2024-06-03 11:27:17 -03:00 committed by GitHub
parent d69cb9f36a
commit 829b6b2095
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 9 deletions

View file

@ -262,15 +262,11 @@ defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do
def deployment_groups(team), do: TeamClient.get_deployment_groups(team.id)
def get_app_specs(team) do
app_deployments = TeamClient.get_agent_app_deployments(team.id)
for app_deployment <- app_deployments do
{seconds, _} = NaiveDateTime.to_gregorian_seconds(app_deployment.deployed_at)
for app_deployment <- TeamClient.get_agent_app_deployments(team.id) do
%Livebook.Apps.TeamsAppSpec{
slug: app_deployment.slug,
version: "#{app_deployment.id}-#{seconds}-#{app_deployment.sha}",
hub_id: team.id,
version: app_deployment.version,
hub_id: app_deployment.hub_id,
app_deployment_id: app_deployment.id
}
end

View file

@ -454,6 +454,7 @@ defmodule Livebook.Hubs.TeamClient do
%Teams.AppDeployment{
id: app_deployment.id,
slug: app_deployment.slug,
version: app_deployment.version,
sha: app_deployment.sha,
title: app_deployment.title,
multi_session: app_deployment.multi_session,

View file

@ -7,6 +7,7 @@ defmodule Livebook.Teams.AppDeployment do
@type t :: %__MODULE__{
id: String.t() | nil,
slug: String.t() | nil,
version: String.t() | nil,
sha: String.t() | nil,
title: String.t() | nil,
multi_session: boolean(),
@ -23,6 +24,7 @@ defmodule Livebook.Teams.AppDeployment do
@primary_key {:id, :string, autogenerate: false}
embedded_schema do
field :slug, :string
field :version, :string
field :sha, :string
field :title, :string
field :multi_session, :boolean

View file

@ -255,6 +255,7 @@ defmodule Livebook.Hubs.TeamClientTest do
%LivebookProto.AppDeployment{
id: app_deployment.id,
title: app_deployment.title,
version: app_deployment.version,
slug: app_deployment.slug,
sha: app_deployment.sha,
deployed_by: app_deployment.deployed_by,
@ -656,9 +657,11 @@ defmodule Livebook.Hubs.TeamClientTest do
# Since the app deployment struct generation is from Livebook side,
# we don't have yet the information about who deployed the app,
# so we need to add it ourselves.
app_deployment = %{
app_deployment
| id: to_string(teams_app_deployment.id),
version: Livebook.Utils.random_id(),
file: nil,
deployed_by: teams_app_deployment.app_revision.created_by.name,
deployed_at: teams_app_deployment.updated_at
@ -670,6 +673,7 @@ defmodule Livebook.Hubs.TeamClientTest do
%LivebookProto.AppDeployment{
id: app_deployment.id,
title: app_deployment.title,
version: app_deployment.version,
slug: app_deployment.slug,
sha: app_deployment.sha,
deployed_by: app_deployment.deployed_by,

View file

@ -104,12 +104,18 @@ defmodule Livebook.Factory do
content = :crypto.strong_rand_bytes(1024 * 1024)
md5_hash = :crypto.hash(:md5, content)
shasum = Base.encode16(md5_hash, case: :lower)
deployed_at = NaiveDateTime.utc_now()
deployed_at =
NaiveDateTime.utc_now()
|> NaiveDateTime.truncate(:second)
{seconds, 0} = NaiveDateTime.to_gregorian_seconds(deployed_at)
%Livebook.Teams.AppDeployment{
id: "1",
title: unique_value("MyNotebook-"),
sha: shasum,
version: "1-#{shasum}-#{seconds}",
slug: slug,
file: content,
multi_session: false,
@ -117,7 +123,7 @@ defmodule Livebook.Factory do
hub_id: Livebook.Hubs.Personal.id(),
deployment_group_id: "1",
deployed_by: "Ada Lovelace",
deployed_at: NaiveDateTime.truncate(deployed_at, :second)
deployed_at: deployed_at
}
end