Skip to content

Commit

Permalink
Clean up deployment state validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Oct 17, 2024
1 parent c82d689 commit 5bd4975
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lib/uplink/packages/instance/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Uplink.Packages.Instance.Bootstrap do
alias Uplink.Repo
alias Uplink.Cache
alias Uplink.Instances

alias Uplink.Members.Actor

alias Uplink.Packages
Expand Down Expand Up @@ -48,29 +47,30 @@ defmodule Uplink.Packages.Instance.Bootstrap do

%Actor{} = actor = Repo.get(Actor, actor_id)

%{install: %Install{deployment: deployment}} =
state =
state =
Install
|> preload([:deployment])
|> Repo.get(install_id)
|> Packages.build_install_state(actor)

if deployment.current_state == "live" do
state
|> handle_placement(instance_params)
|> case do
%{client: _, lxd_project_name: _, placement: _} = updated_state ->
handle_provisioning(updated_state, instance_params)
state
|> handle_placement(instance_params)
|> case do
%{client: _, lxd_project_name: _, placement: _} = updated_state ->
handle_provisioning(updated_state, instance_params)

error ->
handle_error(state, error, instance_params)
end
else
{:snooze, 10}
{:snooze, _} = snooze ->
snooze

error ->
handle_error(state, error, instance_params)
end
end

defp handle_placement(%{install: install} = state, %{"slug" => instance_name}) do
defp handle_placement(
%{install: %{deployment: %{current_state: "live"}} = install} = state,
%{"slug" => instance_name}
) do
placement_name = Placement.name(instance_name)

Instances.mark("executing", install.id, instance_name)
Expand All @@ -80,6 +80,13 @@ defmodule Uplink.Packages.Instance.Bootstrap do
end)
end

defp handle_placement(
%{install: %{deployment: %{current_state: _}}},
_instance_params
) do
{:snooze, 10}
end

defp handle_provisioning(
%{
client: client,
Expand Down

0 comments on commit 5bd4975

Please sign in to comment.