BB.Jido.Action.SafetyAware (bb_jido v0.1.2)

Copy Markdown View Source

Mixin for actions that should refuse to run unless the robot's safety controller is :armed.

Usage

defmodule MyAction do
  use Jido.Action,
    name: "my_action",
    schema: [robot: [type: :atom, required: true]]

  use BB.Jido.Action.SafetyAware

  @impl Jido.Action
  def run(params, context) do
    # only reached when robot is :armed
    {:ok, %{...}}
  end
end

The robot module is looked up first in params[:robot], then in context[:robot]. If the robot is not :armed, the action returns {:error, {:safety_not_armed, state}} without invoking run/2.