View Source Runbox.Runtime.Simple.TemplateCarrier.Snapshot (runbox v17.1.0)

State that is periodically persisted to savepoints and loaded when run continues.

Summary

Functions

Upgrades a possibly old version of the struct to the current version.

Types

@type t() :: %Runbox.Runtime.Simple.TemplateCarrier.Snapshot{
  runbox_version: Version.t(),
  template_state: Runbox.Scenario.Simple.state(),
  timeout_counter: non_neg_integer(),
  timeouts: Heap.t()
}

Functions

Upgrades a possibly old version of the struct to the current version.

The upgrade process is based on steps. Each step applies transformation of the state related to the changes in a specific version. It is similar to database migrations. This function executes all the upgrade steps since the version of the given struct until the struct is upgraded to the current version.

Adding a new upgrade step

For example, if version 42.0.0 adds the field :new_field, then you should create a corresponding clause in the do_upgrade_step/1 function. This clause should upgrade the state from the last preceding version (e.g., 41.1.0) and update the :runbox_version field. Like so:

defp do_upgrade_step(%{runbox_version: %{major: major}} = snapshot) when major < 42 do
  snapshot
  |> Map.put(:new_field, :some_value)
  |> Map.put(:runbox_version, Version.parse!("42.0.0"))
end

Place this new clause right before the catch-all clause (defp do_upgrade_step(snapshot)).