Akd v0.3.0 Akd.Hook behaviour View Source

This module represents an Akd.Hook struct which contains metadata about a hook.

Please refer to Nomenclature for more information about the terms used.

The meta data involves:

  • ensure - A list of Akd.Operation.t structs that run after a deployment, if the hook was successfully executed (independent of whether the deployment itself was successful or not), and run_ensure is true.
  • ignore_failure - If true, the deployment continues to happen even if this hook fails. Defaults to false.
  • main - A list of Akd.Operation.t that run when the hook is executed.
  • rollback - A list of Akd.Operation.t that run when a deployment is a failure, but the hook was called.
  • run_ensure - If true, ensure commands run independent of whether deployment was successful or not. Defaults to true.

This struct is mainly used by native hooks in Akd, but it can be leveraged to write custom hooks.

Link to this section Summary

Types

t()

Generic type for a Hook struct

Functions

This macro allows another module to behave like Akd.Hook. This also allows a module to use Akd.Dsl.FormHook to write readable hooks

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to ensure type

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to main type

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to rollback type

Link to this section Types

Link to this type

t() View Source
t() :: %Akd.Hook{
  ensure: [Akd.Operation.t()],
  ignore_failure: boolean(),
  main: [Akd.Operation.t()],
  rollback: [Akd.Operation.t()],
  run_ensure: boolean()
}

Generic type for a Hook struct

Link to this section Functions

This macro allows another module to behave like Akd.Hook. This also allows a module to use Akd.Dsl.FormHook to write readable hooks.

Examples:

iex> defmodule CustomHook do
...>   use Akd.Hook
...>   def get_hooks(deployment, opts) do
...>     [form_hook do
...>        main "some command", Akd.Destination.local()
...>      end]
...>   end
...> end
iex> CustomHook.get_hooks(nil, nil)
[%Akd.Hook{ensure: [], ignore_failure: false,
      main: [%Akd.Operation{cmd: "some command", cmd_envs: [],
      destination: %Akd.Destination{host: :local, path: ".",
      user: :current}}], rollback: [], run_ensure: true}]
Link to this function

ensure(hook) View Source
ensure(t()) :: list()

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to ensure type.

If run_ensure is false, it doesn't run any operations.

Examples:

iex> hook = %Akd.Hook{}
iex> Akd.Hook.ensure(hook)
{:ok, []}

iex> ensure = [%Akd.Operation{destination: %Akd.Destination{}, cmd: "echo 1"}]
iex> hook = %Akd.Hook{run_ensure: false, ensure: ensure}
iex> Akd.Hook.ensure(hook)
{:ok, []}

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to main type.

Examples:

iex> hook = %Akd.Hook{}
iex> Akd.Hook.main(hook)
{:ok, []}
Link to this function

rollback(hook) View Source
rollback(t()) :: list()

Takes a Akd.Hook.t struct and calls the list of Akd.Operation.t corresponding to rollback type.

Examples:

iex> hook = %Akd.Hook{}
iex> Akd.Hook.rollback(hook)
{:ok, []}

Link to this section Callbacks

Link to this callback

get_hooks(arg0, list) View Source
get_hooks(Akd.Deployment.t(), list()) :: [t()]