Botica.Runner.Sequencer (Botica v2.1.0)

Copy Markdown View Source

Sorts and sequences checks based on their priority and dependencies.

Checks are sorted by priority (lower number = higher priority = runs first). Within the same priority, checks are ordered by their id to ensure deterministic execution order.

Summary

Functions

Filters checks by tags.

Filters checks that have a fix defined.

Groups checks by their tags.

Sorts checks by priority.

Functions

filter_by_tags(checks, tags)

@spec filter_by_tags([Botica.Types.check_def()], [atom()]) :: [
  Botica.Types.check_def()
]

Filters checks by tags.

Examples

iex> checks = [
...>   %{id: :a, name: "A", tags: [:critical]},
...>   %{id: :b, name: "B", tags: [:database]},
...>   %{id: :c, name: "C", tags: [:critical, :database]}
...> ]
iex> Botica.Runner.Sequencer.filter_by_tags(checks, [:critical])
[%{id: :a, name: "A", tags: [:critical]}, %{id: :c, name: "C", tags: [:critical, :database]}]

filter_fixable(checks)

@spec filter_fixable([Botica.Types.check_def()]) :: [Botica.Types.check_def()]

Filters checks that have a fix defined.

Examples

iex> checks = [
...>   %{id: :a, fix: fn -> :ok end},
...>   %{id: :b, fix: nil},
...>   %{id: :c, fix: fn -> :ok end}
...> ]
iex> Botica.Runner.Sequencer.filter_fixable(checks)
[%{id: :a, fix: _}, %{id: :c, fix: _}]

group_by_tags(checks)

@spec group_by_tags([Botica.Types.check_def()]) :: %{
  required(atom()) => [Botica.Types.check_def()]
}

Groups checks by their tags.

Examples

iex> checks = [
...>   %{id: :a, tags: [:critical]},
...>   %{id: :b, tags: [:database]},
...>   %{id: :c, tags: [:critical]}
...> ]
iex> Botica.Runner.Sequencer.group_by_tags(checks)
%{critical: [%{id: :a, tags: [:critical]}, %{id: :c, tags: [:critical]}], database: [%{id: :b, tags: [:database]}]}

sort(checks)

Sorts checks by priority.

Lower priority values run first. When priorities are equal, checks are ordered by their id for determinism.

Examples

iex> checks = [
...>   %{id: :b, name: "B", priority: 2},
...>   %{id: :a, name: "A", priority: 1},
...>   %{id: :c, name: "C", priority: 1}
...> ]
iex> Botica.Runner.Sequencer.sort(checks)
[
  %{id: :a, name: "A", priority: 1},
  %{id: :c, name: "C", priority: 1},
  %{id: :b, name: "B", priority: 2}
]