Packages
altworx_runbox
22.0.0
25.0.0
24.0.0
23.1.0
23.0.0
22.2.0
22.1.0
22.0.0
21.2.0
21.1.2
21.1.1
21.1.0
21.0.0
20.0.0
19.0.0
18.0.0
17.2.0
17.1.0
17.0.1
17.0.0
16.2.0
16.1.0
16.0.0
15.0.0
14.1.0
14.0.1
14.0.0
13.0.3
13.0.2
13.0.1
13.0.0
12.1.0
12.0.0
11.0.1
11.0.0
10.0.0
9.0.0
8.0.0
7.0.1
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.1.3
0.1.2
0.1.1
0.1.0
Runbox is a library for running Altworx scenarios.
Current section
Files
Jump to
Current section
Files
lib/runbox/runtime/state_loader.ex
defmodule Runbox.Runtime.StateLoader do
@moduledoc """
Module handles run state load/initialization.
"""
alias Runbox.Scenario.StartParams
alias Runbox.Scenario.Type
alias Runbox.StateStore
require Logger
@callback load_existing_state(StartParams.t(), instance_ctx :: map(), start_recipe :: []) ::
{:ok, start_recipe :: []} | {:error, :no_savepoint}
@callback init_new_state(StartParams.t(), instance_ctx :: map(), start_recipe :: []) ::
{:ok, start_recipe :: []} | {:error, :no_savepoint}
@doc """
Fetches state into run start recipe.
"""
@spec load(StartParams.t(), map(), start_recipe :: []) ::
{:ok, start_recipe :: []} | {:error, :no_savepoint}
def load(%StartParams{} = start_params, instance_context, start_recipe) do
if StateStore.initialized?(instance_context.state_store_pid) do
{time, res} =
:timer.tc(fn ->
get_impl(start_params.scenario_type).load_existing_state(
start_params,
instance_context,
start_recipe
)
end)
Logger.info("Run #{start_params.run_id} existing state loaded in #{div(time, 1000)}ms.")
res
else
{time, res} =
:timer.tc(fn ->
get_impl(start_params.scenario_type).init_new_state(
start_params,
instance_context,
start_recipe
)
end)
Logger.info("Run #{start_params.run_id} new state loaded in #{div(time, 1000)}ms.")
res
end
end
@stage Type.stage()
@simple Type.simple()
defp get_impl(@stage), do: Runbox.Runtime.Stage.StateLoader
defp get_impl(@simple), do: Runbox.Runtime.Simple.StateLoader
end