diff --git a/lib/uplink/packages/deployment/prepare.ex b/lib/uplink/packages/deployment/prepare.ex index 3747e339..06b83121 100644 --- a/lib/uplink/packages/deployment/prepare.ex +++ b/lib/uplink/packages/deployment/prepare.ex @@ -27,7 +27,11 @@ defmodule Uplink.Packages.Deployment.Prepare do |> Repo.get(deployment_id) |> Repo.preload([:app]) - handle_prepare(deployment, actor) + if deployment.current_state == "live" do + {:ok, :already_live} + else + handle_prepare(deployment, actor) + end end defp handle_prepare( diff --git a/mix.exs b/mix.exs index 4a3f471c..08e6f13a 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Uplink.MixProject do def project do [ app: :uplink, - version: "0.9.12", + version: "0.9.13", elixir: "~> 1.9", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, diff --git a/test/uplink/packages/deployment/prepare_test.exs b/test/uplink/packages/deployment/prepare_test.exs index 0ac69433..d554d118 100644 --- a/test/uplink/packages/deployment/prepare_test.exs +++ b/test/uplink/packages/deployment/prepare_test.exs @@ -67,7 +67,7 @@ defmodule Uplink.Packages.Deployment.PrepareTest do {:ok, _installation} = Packages.create_install(deployment, 1) - {:ok, _transition} = + {:ok, %{resource: deployment}} = Packages.transition_deployment_with(deployment, actor, "prepare") {:ok, actor: actor, deployment: deployment, bypass: bypass} @@ -90,4 +90,21 @@ defmodule Uplink.Packages.Deployment.PrepareTest do actor_id: actor.id }) end + + describe "already live" do + setup %{deployment: deployment, actor: actor} do + {:ok, %{resource: deployment}} = + Packages.transition_deployment_with(deployment, actor, "complete") + + {:ok, deployment: deployment} + end + + test "dont prepare again", %{deployment: deployment, actor: actor} do + assert {:ok, :already_live} = + perform_job(Prepare, %{ + deployment_id: deployment.id, + actor_id: actor.id + }) + end + end end