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
Callbacks
@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.
@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.
@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
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 tonil
, which runs all stages.context
- Metadata to insert into the Lifecycle for use during execution. Defaults tonil
.
Runs all steps in a given Lifecycle.
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.
@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
@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.
@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.