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 ofAkd.Operation.t
structs that run after a deployment, if the hook was successfully executed (independent of whether the deployment itself was successful or not), andrun_ensure
istrue
.ignore_failure
- Iftrue
, the deployment continues to happen even if this hook fails. Defaults tofalse
.main
- A list ofAkd.Operation.t
that run when the hook is executed.rollback
- A list ofAkd.Operation.t
that run when a deployment is a failure, but the hook was called.run_ensure
- Iftrue
,ensure
commands run independent of whether deployment was successful or not. Defaults totrue
.
This struct is mainly used by native hooks in Akd
, but it can be leveraged
to write custom hooks.
Link to this section Summary
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
t()
View Source
t() :: %Akd.Hook{
ensure: [Akd.Operation.t()],
ignore_failure: boolean(),
main: [Akd.Operation.t()],
rollback: [Akd.Operation.t()],
run_ensure: boolean()
}
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
__using__(_) View Source (macro)
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}]
ensure(hook) View Source
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, []}
main(hook) View Source
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, []}
rollback(hook) View Source
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
get_hooks(arg0, list)
View Source
get_hooks(Akd.Deployment.t(), list()) :: [t()]
get_hooks(Akd.Deployment.t(), list()) :: [t()]