View Source Beacon.Lifecycle behaviour (Beacon v0.2.1)

Beacon is open for extensibility by allowing users to inject custom steps into its internal lifecycle.

You can add or overwrite those steps in Beacon.Config.lifecycle/0.

Each one of these functions will be called in specific places inside Beacon's lifecycle, executing the steps defined in the site config.

See each function doc for more info and also Beacon.Config.

Summary

Callbacks

Logic to put metadata from a given context into a Beacon.Lifecycle. The Beacon.Config will also be available here if needed.

Logic to validate that a given Beacon.Lifecycle was initialized properly, according to the given Beacon.Config. A sub-key may be provided if only one lifecycle stage is to be validated, otherwise nil is expected for the third argument.

After executing all the steps of a Beacon.Lifecycle, it is passed here to validate that the output is as-expected. The Beacon.Config will also be available here if needed.

Functions

Initializes a Beacon.Lifecycle with given lifecycle_name and resource, runs all steps for each lifecycle stage, and returns the Lifecycle with result stored in its :output key.

Runs all steps in a given Lifecycle.

This function delegates to the put_metadata/3 callback implemented by the provider module.

Fetches the steps for a given Lifecycle from the provided Beacon.Config and puts those steps into the Lifecycle.

This function delegates to the validate_input!/3 callback implemented by the provider module.

This function delegates to the validate_output!/3 callback implemented by the provider module.

Types

@type t() :: %Beacon.Lifecycle{
  metadata: term(),
  name: atom(),
  output: term(),
  resource: term(),
  steps: list()
}

Callbacks

Link to this callback

put_metadata(lifecycle, config, context)

View Source (optional)
@callback put_metadata(lifecycle :: t(), config :: Beacon.Config.t(), context :: term()) ::
  t()

Logic to put metadata from a given context into a Beacon.Lifecycle. The Beacon.Config will also be available here if needed.

Link to this callback

validate_input!(lifecycle, config, subkey)

View Source (optional)
@callback validate_input!(lifecycle :: t(), config :: Beacon.Config.t(), subkey :: atom()) ::
  t()

Logic to validate that a given Beacon.Lifecycle was initialized properly, according to the given Beacon.Config. A sub-key may be provided if only one lifecycle stage is to be validated, otherwise nil is expected for the third argument.

Link to this callback

validate_output!(lifecycle, config, subkey)

View Source (optional)
@callback validate_output!(
  lifecycle :: t(),
  config :: Beacon.Config.t(),
  subkey :: atom()
) :: t()

After executing all the steps of a Beacon.Lifecycle, it is passed here to validate that the output is as-expected. The Beacon.Config will also be available here if needed.

Functions

Link to this function

execute(provider, site, lifecycle_name, resource, opts \\ [])

View Source
@spec execute(module(), Beacon.Types.Site.t(), atom(), term(), keyword()) :: t()

Initializes a Beacon.Lifecycle with given lifecycle_name and resource, runs all steps for each lifecycle stage, and returns the Lifecycle with result stored in its :output key.

Expects a provider which implements callbacks for validation before and after execution, as well as the logic for parsing contextual metadata.

Options

  • :sub_key - The name of a specific lifecycle stage to execute. If provided, all other stages will be skipped. Defaults to nil, which runs all stages.
  • context - Metadata to insert into the Lifecycle for use during execution. Defaults to nil.
Link to this function

execute_steps(lifecycle)

View Source
@spec execute_steps(t()) :: t()

Runs all steps in a given Lifecycle.

Link to this function

put_metadata(lifecycle, provider, config, context)

View Source

This function delegates to the put_metadata/3 callback implemented by the provider module.

If the callback is not implemented, this will be a no-op.

Link to this function

put_steps(lifecycle, config, sub_key \\ nil)

View Source
@spec put_steps(t(), Beacon.Config.t(), atom()) :: t()

Fetches the steps for a given Lifecycle from the provided Beacon.Config and puts those steps into the Lifecycle.

A sub_key may be provided to only consider the steps for a single lifecycle stage

Link to this function

validate_input!(lifecycle, provider, config, sub_key)

View Source
@spec validate_input!(t(), module(), Beacon.Config.t(), atom()) :: t()
@spec validate_input!(t(), module(), Beacon.Config.t(), term()) :: t()

This function delegates to the validate_input!/3 callback implemented by the provider module.

If the callback is not implemented, this will be a no-op.

Link to this function

validate_output!(lifecycle, provider, config, sub_key)

View Source
@spec validate_output!(t(), module(), Beacon.Config.t(), atom()) :: t()

This function delegates to the validate_output!/3 callback implemented by the provider module.

If the callback is not implemented, this will be a no-op.