From e29e9d600cdab664baed12c426f677a4fa2ae60a Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Thu, 4 Jul 2024 14:29:13 +0700 Subject: [PATCH 1/3] utilize instance wait time from cluster --- lib/icepak/checks.ex | 2 -- lib/icepak/checks/setup.ex | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/icepak/checks.ex b/lib/icepak/checks.ex index 3049aff..9108324 100644 --- a/lib/icepak/checks.ex +++ b/lib/icepak/checks.ex @@ -91,8 +91,6 @@ defmodule Icepak.Checks do "[Checks] ❌ Deactivating #{product["id"]} #{version["serial"]} some checks failed" ) - @polar.transition_version(polar_client, version, %{"name" => "deactivate"}) - raise Icepak.Checks.Setup.CheckFailError, "Some checks have failed, please retry or fix the issue." end diff --git a/lib/icepak/checks/setup.ex b/lib/icepak/checks/setup.ex index a713256..b4231ce 100644 --- a/lib/icepak/checks/setup.ex +++ b/lib/icepak/checks/setup.ex @@ -54,11 +54,13 @@ defmodule Icepak.Checks.Setup do "virtual-machine" => "vm" } - @wait_time %{ + @default_wait_time %{ "container" => 2_000, "vm" => 10_000 } + @increment_wait_time 500 + require Logger def prepare( @@ -114,7 +116,8 @@ defmodule Icepak.Checks.Setup do timeout: 300_000 ) - run_attempt = System.get_env("GITHUB_RUN_ATTEMPT") + run_attempt = System.get_env("GITHUB_RUN_ATTEMPT") || "0" + increment_wait_time = @increment_wait_time * String.to_integer(run_attempt) with {:ok, project_name} <- Testing.get_or_create_project(client), {:ok, %{body: create_operation}} <- @@ -126,7 +129,17 @@ defmodule Icepak.Checks.Setup do {:ok, _wait_start_result} <- @lexdee.wait_for_operation(client, start_operation["id"], query: [timeout: 300]) do if Application.get_env(:icepak, :env) != :test do - wait_time = Map.fetch!(@wait_time, instance_type) * String.to_integer(run_attempt) + instance_wait_time = + Enum.find(cluster["instance_wait_times"], fn iwt -> + iwt["type"] == instance_type + end) + + wait_time = + if instance_wait_time do + instance_wait_time["duration"] + else + Map.fetch!(@default_wait_time, instance_type) + increment_wait_time + end Logger.info( "[#{check_name}] Waiting #{wait_time} ms for #{instance_type} #{instance_name}" From 8aa1156eaec94f178b31416d849c4e594e0efd3f Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Thu, 4 Jul 2024 14:31:12 +0700 Subject: [PATCH 2/3] Add instance_wait_times to cluster --- lib/icepak/checks/setup.ex | 2 +- lib/icepak/polar/cluster.ex | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/icepak/checks/setup.ex b/lib/icepak/checks/setup.ex index b4231ce..3935cfb 100644 --- a/lib/icepak/checks/setup.ex +++ b/lib/icepak/checks/setup.ex @@ -130,7 +130,7 @@ defmodule Icepak.Checks.Setup do @lexdee.wait_for_operation(client, start_operation["id"], query: [timeout: 300]) do if Application.get_env(:icepak, :env) != :test do instance_wait_time = - Enum.find(cluster["instance_wait_times"], fn iwt -> + Enum.find(cluster.instance_wait_times, fn iwt -> iwt["type"] == instance_type end) diff --git a/lib/icepak/polar/cluster.ex b/lib/icepak/polar/cluster.ex index 00df5f0..24c951d 100644 --- a/lib/icepak/polar/cluster.ex +++ b/lib/icepak/polar/cluster.ex @@ -1,13 +1,23 @@ defmodule Icepak.Polar.Cluster do - @derive {Inspect, only: [:id, :type, :arch, :current_state]} - defstruct [:id, :type, :arch, :current_state, :endpoint, :private_key, :certificate] + @derive {Inspect, only: [:id, :type, :arch, :current_state, :instance_wait_times]} + defstruct [ + :id, + :type, + :arch, + :current_state, + :endpoint, + :private_key, + :certificate, + :instance_wait_times + ] def new(%{ "id" => id, "type" => type, "arch" => arch, "current_state" => current_state, - "credential" => credential + "credential" => credential, + "instance_wait_times" => instance_wait_times }) do %__MODULE__{ id: id, @@ -16,7 +26,8 @@ defmodule Icepak.Polar.Cluster do current_state: current_state, endpoint: credential["endpoint"], private_key: credential["private_key"], - certificate: credential["certificate"] + certificate: credential["certificate"], + instance_wait_times: instance_wait_times } end end From 35108c4dee333c5a7c5c6ec8d6978c35b76ea8f8 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Thu, 4 Jul 2024 14:43:16 +0700 Subject: [PATCH 3/3] Version bump --- action.yml | 4 ++-- mix.exs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 838aea7..0df257e 100644 --- a/action.yml +++ b/action.yml @@ -82,14 +82,14 @@ runs: uses: actions/cache@v4 with: path: ~/.mix - key: ${{ runner.arch }}-icepak-1.0.4 + key: ${{ runner.arch }}-icepak-1.0.5 - name: Install Pakman if: steps.cache-icepak.outputs.cache-hit != 'true' run: | mix local.rebar --force mix local.hex --force - mix escript.install hex icepak 1.0.4 --force + mix escript.install hex icepak 1.0.5 --force shell: alpine.sh {0} env: MIX_ENV: prod \ No newline at end of file diff --git a/mix.exs b/mix.exs index 29a5d67..c076f47 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Icepak.MixProject do def project do [ app: :icepak, - version: "1.0.4", + version: "1.0.5", elixir: "~> 1.14", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod,