Orkestra.Command behaviour (orkestra v0.2.0)

Copy Markdown View Source

Behaviour and struct builder for CQRS commands.

A command represents an intent to change the system state. Commands are validated, authorized, and dispatched to a handler.

Defining a command

defmodule MyApp.Tasks.Commands.StartAssessment do
  use Orkestra.Command

  param :repo, :string, required: true
  param :branch, :string, default: "main"
  param :expert_name, :string, required: true
  param :action_name, :string, required: true
  param :montini_software_folder_url, :string, required: true
  param :action_params, :map, default: %{}
end

Building a command

{:ok, cmd} = StartAssessment.new(%{
  repo: "owner/repo",
  expert_name: "architect",
  action_name: "perform-assessment",
  montini_software_folder_url: "tasks/task_123"
})

cmd.id           # auto-generated
cmd.params.repo  # "owner/repo"

Summary

Functions

Declares a command parameter.

Types

param_definition()

@type param_definition() :: {atom(), atom(), keyword()}

t()

@type t() :: %{
  __struct__: atom(),
  id: String.t(),
  type: String.t(),
  params: map(),
  metadata: Orkestra.Metadata.t() | nil
}

Callbacks

param_definitions()

@callback param_definitions() :: [param_definition()]

validate(map)

@callback validate(map()) :: :ok | {:error, term()}

Functions

generate_id()

param(name, type, opts \\ [])

(macro)

Declares a command parameter.